<?php

use api\classes\API;
use bin\php\Classes\pageNavbar;
use bin\php\Classes\formBuilder;

if (!defined('APP_INIT')) {
    exit;
}
# IDE Section

# Includes Section
require_once "{$_SERVER['DOCUMENT_ROOT']}/bin/php/Classes/pageNavbar.php";
require_once "{$_SERVER['DOCUMENT_ROOT']}/bin/php/Classes/formBuilder.php";
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API.php";

# Check permissions
$API = new API();
if (!$API->checkPermissions('admin-access-control-permissions', 'RW', true)) {
    echo 'error 401 unauthorized';
    exit;
}

# Page functions

# JS Scripts to load for this page
$jsScriptLoadData['form'] = true;
$jsScriptLoadData['/src/js/sentri/slugify.js'] = true;
$jsScriptLoadData['/src/js/sentri/breadCrumbs.js'] = true;

# PageClasses Setup
$pageNavbar = new pageNavbar(true);
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_platform') . '</button></a>');
$formBuilder = new formBuilder('add_platform', '<i class="fas fa-edit"></i>', '/platforms/',);
$formBuilder->submitButtonText = __('save');
$formBuilder->submitButtonIcon = '<i class="fas fa-save"></i>';

# Retrieve Information for the page

# Set breadcrumb data
$_SESSION['breadCrumbArray'][] = ['display' => __('platforms'), 'href' => '/platforms/'];
$_SESSION['breadCrumbArray'][] = ['display' => __('add_platform'), 'href' => ''];

# Start page output
$pageNavbar->outPutNavbar();
$formBuilder->startForm();
?>
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/autop/platforms">
    <div class="card-body">
        <div class="form-group form-show-validation row">
            <label for="platform_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_name') ?></label>
            <div class="col-lg-9 col-md-12 col-sm-10">
                <input type="text" class="form-control" id="platform_name" name="platform_name" placeholder="" data-slugify="platform_slugify" required/>
            </div>
        </div>

        <div class="form-group form-show-validation row">
            <label for="platform_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_slugify') ?></label>
            <div class="col-lg-9 col-md-12 col-sm-10">
                <input type="text" class="form-control" id="platform_slugify" name="platform_slugify" placeholder="" required/>
            </div>
        </div>

        <div class="form-group form-show-validation row">
            <label for="platform_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_enabled') ?></label>
            <div class="col-lg-9 col-md-12 col-sm-10">
                <div class="select2-input">
                    <select id="platform_enabled" name="platform_enabled" class="form-control" required>
                        <option value="1" selected><?php echo __('enabled') ?></option>
                        <option value="0"><?php echo __('disabled') ?></option>
                    </select>
                </div>
            </div>
        </div>

        <div class="form-group form-show-validation row">
            <label for="platform_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_description') ?></label>
            <div class="col-lg-9 col-md-12 col-sm-10">
                <textarea class="form-control" id="platform_description" name="platform_description" rows="5"> </textarea>
            </div>
        </div>

        <div class="form-group form-show-validation row">
            <label for="platform_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_image') ?></label>
            <div class="col-lg-9 col-md-12 col-sm-10">
                <div class="input-file input-file-image">
                    <img class="img-upload-preview" width="200" src="/src/images/placeholder200x200.png" alt="preview">
                    <input type="file" class="form-control form-control-file" id="platform_image" name="platform_image" accept="image/png">
                    <label for="platform_image" class="label-input-file btn btn-black btn-round">
                        <span class="btn-label"><i class="fa fa-file-image"></i></span>
                        <?php echo __('upload_image') ?>
                    </label>
                </div>
            </div>
        </div>
    </div>

    <?php $formBuilder->formFooter(); ?>
</form>
<?php $formBuilder->endForm(); ?>
