<?php

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

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

# Includes Section
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_vendors.php');

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

# JS Scripts to load for this page
$jsScriptLoadData['form'] = true;
$jsScriptLoadData['slugify'] = true;
$jsScriptLoadData['breadCrumbs'] = 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_vendor') . '</button></a>');

$formBuilder = new formBuilder('add_vendor', '<i class="fas fa-plus"></i>', '/vendors/');

# Set breadcrumb data
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_vendor'), 'href' => '/vendors/'));

# Retrieve Information for the page


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

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

            <div class="form-group form-show-validation row">
                <label for="vendor_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_enabled') ?></label>
                <div class="col-lg-9 col-md-12 col-sm-10">
                    <div class="select2-input">
                        <select id="vendor_enabled" name="vendor_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="vendor_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_description') ?></label>
                <div class="col-lg-9 col-md-12 col-sm-10">
                    <textarea class="form-control" id="vendor_description" name="vendor_description" rows="5"></textarea>
                </div>
            </div>

            <div class="form-group form-show-validation row">
                <label for="vendor_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_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="vendor_image" name="vendor_image" accept="image/png">
                        <label for="vendor_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(); ?>