<?php require_once ('model.php');
$url = isset($_GET['url']) ? $_GET['url'] : '';
$segments = explode('/', $url);
$id = get_id($segments[3]);
$post = post($id);
?>
<div class="row">
    <div class="col-xxl-12">
        <div class="alert alert-primary alert-border-left alert-dismissible fade show lang_alert" role="alert">
            <i class="ri-error-warning-line me-3 align-middle fs-16"></i>
            <?=lang('form_editing_lang')?> <?=lang_name($post['lang'])?>
        </div>
    </div>
</div>
<form action="<?=ADMIN_URL?>/update" class="needs-validation" novalidate method="POST">
    <input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']['value']; ?>">
    <input type="hidden" name="model" value="<?=$model?>">
    <input type="hidden" name="id" value="<?=$id?>">
    <input type="hidden" name="lang_ref_id" value="<?=$post['lang_ref_id']?>">
    <input type="hidden" name="lang" value="<?=$post['lang']?>">
    <div class="row">
        <div class="col-xxl-10">
            <div class="card">
                <div class="card-header align-items-center d-flex">
                    <h4 class="card-title mb-0 flex-grow-1 text-muted"><?=lang('form_detail')?></h4>
                </div><!-- end card header -->
                <div class="card-body">
                    <div class="live-preview">
                        <div class="row">


                            <div class="col-md-12">
                                <div class="mb-3 input-group-v ">
                                    <label for="title" class="form-label"><?=lang('form_input_title')?></label>
                                    <input type="text" name="title"  class="form-control input-group-flat" value="<?=$post['title']?>" placeholder="<?=lang('form_input_title_placeholder')?>" id="title" required>

                                    <div class="invalid-feedback">
                                        <?=lang('form_vali_title')?>
                                    </div>
                                </div>
                            </div>
                            <!--end col-->

                        </div>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0"><?=lang('table_slider_items_title', [], 'Slider Öğeleri')?></h4>
                </div><!-- end card header -->

                <div class="card-body">
                    <div class="listjs-table" id="customerList">
                        <div class="row g-4 mb-3">
                            <div class="col-sm-auto">
                                <div>
                                    <button type="button" class="btn btn-success add-btn" data-bs-toggle="modal" id="slider_item_create" data-bs-target="#slider_item_form"><i class="ri-add-line align-bottom me-1"></i> <?=lang('create')?></button>
<!--                                    <button class="btn btn-soft-danger" onclick="deleteMultiple()"><i class="ri-delete-bin-2-line"></i></button>-->
                                </div>
                            </div>
                        </div>

                        <div class="table-responsive table-card mt-3 mb-1">
                            <table class="table align-middle table-nowrap" id="customerTable">
                                <thead class="table-light">
                                <tr>
                                    <th scope="col" style="width: 50px;">
                                        <div class="form-check">
                                            <input class="form-check-input" type="checkbox" id="checkAll" value="option">
                                        </div>
                                    </th>
                                    <th class="sort" data-sort="image"><?=lang('table_image', [], 'Görsel')?></th>
                                    <th class="sort" data-sort="title"><?=lang('table_title')?></th>
                                    <th class="sort" data-sort="order"><?=lang('table_order', [], 'Sıra')?></th>
                                    <th data-sort="action" style="width: 130px;">&nbsp;</th>
                                </tr>
                                </thead>
                                <tbody class="list form-check-all">
                                <?php
                                    foreach (slider_Items('data', $id) as $slider_Item){
                                ?>
                                    <tr>
                                        <th scope="row">
                                            <div class="form-check">
                                                <input class="form-check-input" type="checkbox" name="chk_child" value="option1">
                                            </div>
                                        </th>
                                        <td class="image"><img src="<?=UPLOAD_URL?><?=$slider_Item['image']?>" class="slider_image"></td>
                                        <td class="title"><?=$slider_Item['title']?></td>
                                        <td class="order"><?=$slider_Item['short']?></td>
                                        <td>
                                            <div class="d-flex gap-2">
                                                <div class="edit">
                                                    <a href="#" class="edit-item-btn" data-bs-toggle="modal" data-bs-target="#slider_item_form" data-id="<?=$slider_Item['id']?>">
                                                        <i class="bx bx-edit edit_icon" style=""></i>
                                                    </a>
                                                </div>
                                                <div class="remove">
                                                    <a href="#" id="slider_item_delete" data-id="<?=$slider_Item['id']?>" data-slider="<?=$id?>" data-title="<?=lang('remove_title')?>" data-question="<?=lang('remove_desc')?>" data-no="<?=lang('no')?>"  data-yes="<?=lang('yes')?>" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="<?=lang('remove')?>">
                                                        <i class="bx bx-trash trash_icon" style=""></i>
                                                    </a>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                <?php  } ?>
                                </tbody>
                            </table>
                            <div class="noresult" style="display: none">
                                <div class="text-center">
                                    <lord-icon src="https://cdn.lordicon.com/msoeawqm.json" trigger="loop" colors="primary:#121331,secondary:#08a88a" style="width:75px;height:75px"></lord-icon>
                                    <h5 class="mt-2"><?=lang('table_noresult_title')?></h5>
                                    <p class="text-muted mb-0"><?=lang('table_noresult_desc')?></p>
                                </div>
                            </div>
                        </div>

                        <div class="d-flex justify-content-end">
                            <div class="d-flex justify-content-end">
                                <div class="pagination-wrap hstack gap-2">
                                    <a class="page-item pagination-prev disabled" href="javascrpit:void(0);">
                                        <?=lang('table_prev')?>
                                    </a>
                                    <ul class="pagination listjs-pagination mb-0"></ul>
                                    <a class="page-item pagination-next" href="javascrpit:void(0);">
                                        <?=lang('table_next')?>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div><!-- end card -->
            </div>        </div> <!-- end col -->

        <div class="col-xxl-2">
            <div class="card card-body">
                <h4 class="card-title  flex-grow-1 text-muted"><?=lang('published')?></h4>
                <hr>
                <div class="saved">
                    <button class="btn btn-primary" type="submit" value="save_and_edit" name="save_and_edit">
                <span class="icon-tabler-wrapper icon-left">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-floppy" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                      <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                      <path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2"></path>
                      <path d="M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"></path>
                      <path d="M14 4l0 4l-6 0l0 -4"></path>
                    </svg>
                </span>
                        <?=lang('save_and_edit')?>
                    </button>
                    <button class="btn btn-light" type="submit" name="save" value="save">
                <span class="icon-tabler-wrapper icon-left">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-transfer-in" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                      <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                      <path d="M4 18v3h16v-14l-8 -4l-8 4v3"></path>
                      <path d="M4 14h9"></path>
                      <path d="M10 11l3 3l-3 3"></path>
                    </svg>
                </span>
                        <?=lang('save')?>
                    </button>
                </div>
            </div>
            <div class="card card-body">
                <h4 class="card-title  flex-grow-1 text-muted"><?=lang('page_title_languages')?></h4>
                <hr>
                <div class="list-others-language">
                    <?php foreach (posts_langs($post['lang_ref_id'], lang_is_default('lang_code')) as $posts_lang){
                        if ($posts_lang['lang'] != $post['lang']) {
                            ?>
                            <a class="gap-2 d-flex align-items-center text-decoration-none" href="<?=$posts_lang['id']?>" target="_blank">
                                <img src="<?=ADMIN_FOLDER?>/model/languages/flags/<?=$posts_lang['lang']?>.svg" title="<?=lang_name($posts_lang['lang'])?>" class="flag" style="height: 16px" alt="<?=lang_name($posts_lang['lang'])?> Bayrak">
                                <span><?=lang_name($posts_lang['lang'])?> <span class="icon-tabler-wrapper"><i class="bx bx-edit"></i></span></span>
                            </a>
                        <?php }} ?>
                </div>
            </div>

            <div class="card card-body">
                <h4 class="card-title  flex-grow-1 text-muted"><?=lang('status')?></h4>
                <hr>
                <select class="form-select mb-3" name="status">
                    <option <?php echo ($post['status'] == 1) ? 'selected="selected"' : ''; ?> value="1"><?=lang('status_option_published')?> </option>
                    <option <?php echo ($post['status'] == 2) ? 'selected="selected"' : ''; ?> value="2"><?=lang('status_option_draft')?> </option>
                    <option <?php echo ($post['status'] == 0) ? 'selected="selected"' : ''; ?> value="0"><?=lang('status_option_unpublished')?> </option>
                </select>
            </div>
        </div> <!-- end col -->
    </div>


</form>

<div class="modal fade" id="slider_item_form" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header bg-light p-3">
                <h5 class="modal-title" id="exampleModalLabel"></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" id="close-modal"></button>
            </div>
            <form class="slider_item_form" autocomplete="off">
                <div class="modal-body">
                    <input type="hidden" name="type" id="type" value="save">
                    <input type="hidden" name="slider_item_id" id="slider_item_id" value="">
                    <input type="hidden" name="slider_id" value="<?=$id?>">
                   <div class="mb-3">
                       <label for="title" class="form-label"><?=lang('table_image', [], 'Görsel')?></label>
                       <input type="hidden"  data-v-image name="image" id="featured-image-input" value="">
                       <img data-v-image src="<?=ADMIN_THEME_URL?>/assets/images/placeholder.svg" alt="" id="featured-image-thumb"  data-media-gallery data-target-input="#featured-image-input" data-target-thumb="#featured-image-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle">
                       <div class="py-3 text-center">
                           <div class="btn-group w-100">
                               <button type="button" class="btn btn-primary btn-icon btn-sm w-100" data-media-gallery data-target-input="#featured-image-input" data-target-thumb="#featured-image-thumb" data-type="single">
                                   <i class="la la-image la-lg"></i> <?=lang('set_media')?>
                               </button>

                               <button type="button" class="btn btn-outline-secondary btn-icon btn-sm" onclick="clearFeaturedMedia()">
                                   <i class="la la-times"></i>
                               </button>
                           </div>
                       </div>
                    </div>
                    <div class="mb-3">
                        <label for="title" class="form-label"><?=lang('form_input_title')?></label>
                        <input type="text" id="item_title" name="item_title" class="form-control" placeholder="<?=lang('form_input_title')?>" required="">
                    </div>

                    <div class="mb-3">
                        <label for="sub_title" class="form-label"><?=lang('form_input_sub_title', [], 'Alt Başlık')?></label>
                        <input type="text" id="sub_title" name="subtitle" class="form-control" placeholder="<?=lang('form_input_sub_title', [], 'Alt Başlık')?>">
                    </div>

                    <div class="mb-3">
                        <label for="decription" class="form-label"><?=lang('form_input_description')?></label>
                        <textarea class="form-control" id="description" name="description"></textarea>
                    </div>

                    <div class="mb-3">
                        <label for="button_label_1" class="form-label"><?=lang('form_input_button_label')?> 1</label>
                        <input type="text" id="button_label_1" name="button1_label" class="form-control" placeholder="<?=lang('form_input_button_label')?> 1" >
                    </div>
                    <div class="mb-3">
                        <label for="button_link_1" class="form-label"><?=lang('form_input_button_url')?> 1</label>
                        <input type="text" id="button_link_1" name="button1_link" class="form-control" placeholder="<?=lang('form_input_button_url')?> 1">
                    </div>
                    <div class="mb-3">
                        <label for="button_label_2" class="form-label"><?=lang('form_input_button_label')?> 2</label>
                        <input type="text" id="button_label_2" name="button2_label" class="form-control" placeholder="<?=lang('form_input_button_label')?> 2" >
                    </div>
                    <div class="mb-3">
                        <label for="button_link_2" class="form-label"><?=lang('form_input_button_url')?> 2</label>
                        <input type="text" id="button_link_2" name="button2_link" class="form-control" placeholder="<?=lang('form_input_button_url')?> 2">
                    </div>
                    <div class="mb-3">
                        <label for="button_link_2" class="form-label"><?=lang('table_order', [], 'Sıra')?></label>
                        <input type="number" id="short" name="short" class="form-control" placeholder="<?=lang('table_order', [], 'Sıra')?>">
                    </div>
                    <div class="modal-footer">
                    <div class="hstack gap-2 justify-content-end">
                        <button type="button" class="btn btn-light" data-bs-dismiss="modal"><?=lang('menu_button_cancel', [], 'İptal')?></button>
                        <button class="btn btn-primary" type="submit" value="save_and_edit" name="save_and_edit">
                            <span class="icon-tabler-wrapper icon-left">
                                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-floppy" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                                  <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                  <path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2"></path>
                                  <path d="M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"></path>
                                  <path d="M14 4l0 4l-6 0l0 -4"></path>
                                </svg>
                            </span>
                            <?=lang('save')?>
                        </button>
                        <!-- <button type="button" class="btn btn-success" id="edit-btn">Update</button> -->
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

