<?php require PATH . '/view/common/head.php'; ?>
<?php require PATH . '/view/common/header.php'; ?>
<?php if(isset($Listing['resolution'])) $Resolution = explode('x', $Listing['resolution']);?>
<form method="post" enctype="multipart/form-data">
    <input type="hidden" name="_ACTION" value="save">
    <input type="hidden" name="_TOKEN" value="<?php echo $Token?>">
    <div class="row gx-xl-4 h-100 justify-content-center">
        <div class="col-lg">
            <div class="card rounded-3 shadow-none border-0">
                <div class="card-body px-xxl-5">
                    <div class="mb-3 text-center">
                        <div class="form-selectgroup bg-white">
                            <label class="form-selectgroup-item">
                                <input type="radio" name="type" value="upload" class="form-selectgroup-input" <?php if(empty($Listing['type']) || $Listing['type']=='upload' ) echo 'checked=""' ; ?>
                                data-ajax="type" data-form="category">
                                <div class="form-selectgroup-label">
                                    <?php echo $this->translate('Upload game');?>
                                </div>
                            </label>
                            <label class="form-selectgroup-item">
                                <input type="radio" name="type" value="remote" class="form-selectgroup-input" <?php if(isset($Listing['type']) && $Listing['type']=='remote' ) echo 'checked=""' ; ?>
                                data-ajax="type">
                                <div class="form-selectgroup-label">
                                    <?php echo $this->translate('Remote add');?>
                                </div>
                            </label>
                            <a href="<?php echo APP.'/admin/tools';?>" target="_blank" class="form-selectgroup-item">
                                <div class="form-selectgroup-label">
                                    <?php echo $this->translate('Fetch game');?>
                                </div>
                            </a>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Title');?></label>
                        <input type="text" name="title" class="form-control form-control-lg" placeholder="<?php echo $this->translate('Title');?>" required="true" value="<?php if(isset($Listing['title'])) echo $Listing['title'];?>">
                        <?php if(isset($Listing['self'])) { ?>
                        <div class="fs-xs mt-2">
                            <span class="fw-semibold">Permalink : </span>
                            <span class="permalink">
                                <?php echo APP;?>/<input type="text" name="self" class="form-control d-inline-block fs-xs py-0 bg-transparent border-0 shadow-none px-0 fw-semibold w-auto" value="<?php echo $Listing['self'];?>"></span>
                        </div>
                        <?php } ?>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Category');?></label>
                        <div>
                            <select name="categories[]" class="bs-select" multiple data-live-search="true" required="true">
                                <?php foreach($Categories as $Category) { ?>
                                <option value="<?php echo $Category['id'];?>" <?php if(isset($Selected) && in_array($Category['id'], $Selected)) echo ' selected=""' ;?>
                                    <?php echo 'data-text="'.$Category['name'].'"';?>>
                                    <?php echo $Category['name'];?>
                                </option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Description');?></label>
                        <textarea name="description" class="form-control" rows="3" placeholder="<?php echo $this->translate('Description');?>"><?php if(isset($Listing['description'])) echo $Listing['description'];?></textarea>
                    </div>
                    <div class="mb-3 remote d-none">
                        <div class="mb-3">
                            <label class="form-label">
                                <?php echo $this->translate('Image URL');?></label>
                            <input type="text" name="image_url" class="form-control" placeholder="https://" value="" maxlength="255">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">
                                <?php echo $this->translate('Game URL');?></label>
                            <input type="text" name="source" class="form-control" placeholder="https://" value="<?php echo (isset($Listing['type']) AND $Listing['type']) == 'remote' ? $Listing['source'] : null;?>" maxlength="255">
                        </div>
                    </div>
                    <div class="mb-3 upload d-none">
                        <label class="form-label">
                            <?php echo $this->translate('Game File');?> (.ZIP)</label>
                        <input class="form-control" type="file" name="file" id="formFile">
                        <div class="mt-2 text-muted fs-xs">
                            <div class="py-1">
                                <?php echo $this->translate('Must contain index.html on root');?>
                            </div>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Control');?></label>
                        <textarea name="control" class="form-control" rows="3" placeholder="<?php echo $this->translate('Control');?>"><?php if(isset($Listing['control'])) echo $Listing['control'];?></textarea>
                    </div>
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="mb-3">
                                <label class="form-label">
                                    <?php echo $this->translate('Width');?></label>
                                <input type="text" name="width" class="form-control" placeholder="<?php echo $this->translate('Width');?>" value="<?php echo isset($Resolution[1]) ? $Resolution[0] : IFRAME_X;?>" maxlength="25">
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="mb-3">
                                <label class="form-label">
                                    <?php echo $this->translate('Height');?></label>
                                <input type="text" name="height" class="form-control" placeholder="<?php echo $this->translate('Height');?>" value="<?php echo isset($Resolution[1]) ? $Resolution[1] : IFRAME_Y;?>" maxlength="25">
                            </div>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Keywords');?></label>
                        <input type="text" name="keywords" value="<?php echo isset($Listing['keywords']) ? $Listing['keywords'] : (isset($_POST['keywords']) ? $_POST['keywords'] : null);?>" class="form-control" placeholder="<?php echo $this->translate('Keyword1, Keyword2');?>">
                    </div>
                    <hr class="my-4">
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Meta title');?></label>
                        <input type="text" name="meta_title" class="form-control" placeholder="<?php echo $this->translate('Meta title');?>" value="<?php echo isset($Listing['meta_title']) ? $Listing['meta_title'] : null;?>" maxlength="25">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">
                            <?php echo $this->translate('Meta description');?></label>
                        <textarea name="meta_description" class="form-control" rows="3" maxlength="255" placeholder="<?php echo $this->translate('Meta description');?>"><?php if(isset($Listing['meta_description'])) echo $Listing['meta_description'];?></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-auto">
            <div class="h-100 w-xl-300 border-start border-gray-100">
                <div class="mb-3">
                    <div class="ratio-select ratio ratio-cover rounded bg-img-cover position-relative input-cover" style="--bs-aspect-ratio: 100%;background-image: url(<?php if(isset($Listing['image'])) echo UPLOAD.'/'.GAME_FOLDER.'/'.$Listing['image']; ?>);">
                        <div class="ratio-preview text-muted <?php if($Listing['image']) echo 'd-none';?> d-flex align-items-center justify-content-center">
                            <div class="text-center">
                                <svg width="34" height="34" fill="none" stroke="currentColor" stroke-width="1.75">
                                    <use xlink:href="<?php echo ASSETS.'/sprite/sprite.svg#image';?>"></use>
                                </svg>
                                <div class="fs-base mt-2">
                                    <?php echo $this->translate('Select image');?>
                                </div>
                                <div class="fs-xs">
                                    <?php echo $this->translate('Allow image type jpg, png, webp');?>
                                </div>
                            </div>
                        </div>
                        <div class="ratio-btn">
                            <button class="btn btn-square p-0 rounded-circle btn-primary mx-1 btn-upload" data-id="input-cover">
                                <svg width="16" height="16" stroke="currentColor" stroke-width="2" fill="none">
                                    <use xlink:href="<?php echo ASSETS.'/sprite/sprite.svg#upload';?>"></use>
                                </svg>
                            </button>
                            <button class="btn btn-square p-0 rounded-circle btn-light mx-1 btn-clear <?php if(empty($Listing['image'])) echo 'd-none';?>" data-id="input-cover">
                                <svg width="18" height="18" stroke="currentColor" stroke-width="2" fill="none">
                                    <use xlink:href="<?php echo ASSETS.'/sprite/sprite.svg#close';?>"></use>
                                </svg>
                            </button>
                        </div>
                    </div>
                    <input type="file" name="image" class="ratio-input d-none" id="file-input-cover" data-preview="ratio-cover" accept="image/*">
                </div>
                <div class="d-grid mb-3">
                    <button type="submit" class="btn btn-primary px-xl-7 py-3">
                        <?php echo $this->translate('Save changes');?></button>
                </div>
                <div class="mb-3">
                    <label class="form-label fs-xs">
                        <?php echo $this->translate('Advanced');?></label>
                    <div class="form-switch mb-1">
                        <input class="form-check-input" type="checkbox" id="status" name="status" value="1" <?php if(empty($Listing['status']) || $Listing['status'] !=2) echo 'checked' ;?>>
                        <label class="form-check-label" for="status">
                            <?php echo $this->translate('Publish');?></label>
                    </div>
                    <div class="form-switch mb-3">
                        <input class="form-check-input" type="checkbox" id="featured" name="featured" value="1" <?php if(isset($Listing['featured']) AND $Listing['featured']==1) echo 'checked' ;?>>
                        <label class="form-check-label" for="featured">
                            <?php echo $this->translate('Featured');?></label>
                    </div>
                    <div class="form-switch mb-1">
                        <input class="form-check-input" type="checkbox" id="member" name="member" value="1" <?php if(isset($Listing['member']) AND $Listing['member']==1) echo 'checked' ;?>>
                        <label class="form-check-label" for="member">
                            <?php echo $this->translate('Members only');?></label>
                    </div>
                    <div class="form-switch mb-1">
                        <input class="form-check-input" type="checkbox" id="comment" name="comment" value="1" <?php if(isset($Listing['comment']) AND $Listing['comment']=='1' ) echo 'checked="true"' ;?>>
                        <label class="form-check-label" for="comment">
                            <?php echo $this->translate('Closed comment');?></label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<?php require PATH . '/view/common/javascript.php'; ?>
<?php require PATH . '/view/common/footer.php'; ?>