<?php
if (m_u_g('lang')){
   $lang = m_u_g('lang');
}else{
    $lang = lang_is_default('lang_code');
}

?>
<?php
$active_theme = get_active_theme();
$theme_info_file = ROOT_FOLDER . '/theme/' . $active_theme . '/theme.json';
$theme_title = ucfirst($active_theme);

if (file_exists($theme_info_file)) {
    $theme_info = json_decode(file_get_contents($theme_info_file), true);
    $theme_title = isset($theme_info['title']) ? $theme_info['title'] : ucfirst($active_theme);
}
?>

<div class="row">
    <div class="col-xxl-12">
        <div class="alert alert-success alert-border-left alert-dismissible fade show" role="alert">
            <i class="ri-information-line me-3 align-middle fs-16"></i>
            <strong><?= $theme_title ?></strong> <?= lang('theme_options.scope_note', [], 'teması için özel ayarları düzenliyorsunuz. Bu ayarlar sadece bu temaya özgüdür.') ?>
        </div>
    </div>
</div>
<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($lang)?>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-xxl-12">
        <div class="row align-items-center">
            <div class="col-md-10">
                <h5 class="mb-3" style="float: left;"><?=lang('page_title_theme_options', [], 'Tema Ayarları')?></h5>
            </div>
            <div class="col-md-2">
                <ul class="list-wrap" style="float: right;">
                    <?php
                    $languages = languages('data');
                    foreach ($languages as $language){
                        ?>
                        <li style="display: inline-block; margin-right: 5px;"><a href="?lang=<?=$language['lang_code']?>"><img src="<?=ADMIN_FOLDER?>/model/languages/flags/<?=$language['lang_code']?>.svg"></a></li>
                        <?php
                    }
                    ?>
                </ul>
            </div>
        </div>
    </div>
        <?php if (!function_exists('can') || can('edit','theme_options')): ?>
        <form action="<?=ADMIN_URL?>/settings" method="POST">
            <input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']['value']; ?>">
            <input type="hidden" name="get_lang" value="<?php echo $lang ?>">
            <input type="hidden" name="form_type" value="theme_options">

            <div class="card">
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="nav flex-column nav-pills text-left" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                                <a class="nav-link mb-2 active" id="v-pills-general-tab" data-bs-toggle="pill" href="#v-pills-general" role="tab" aria-controls="v-pills-general" aria-selected="true">
                                    <svg class="icon me-2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                        <path d="M5 12l-2 0l9 -9l9 9l-2 0"></path>
                                        <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7"></path>
                                        <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0  0 1 2 2v6"></path>
                                    </svg>
                                    <?= lang('theme_options.tab.general', [], 'Tema Ayarları') ?>
                                </a>
                                <a class="nav-link mb-2" id="v-pills-logo-tab" data-bs-toggle="pill" href="#v-pills-logo" role="tab" aria-controls="v-pills-logo" aria-selected="false">
                                    <svg class="icon me-2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                        <path d="M15 8h.01"></path>
                                        <path d="M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12z"></path>
                                        <path d="M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5"></path>
                                        <path d="M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3"></path>
                                    </svg>
                                    <?= lang('theme_options.tab.logo', [], 'Logo & Favicon') ?>
                                </a>
                                <a class="nav-link mb-2" id="v-pills-social-links-tab" data-bs-toggle="pill" href="#v-pills-social-links" role="tab" aria-controls="v-pills-social-links" aria-selected="false">
                                    <svg class="icon me-2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                        <path d="M6 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
                                        <path d="M18 6m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
                                        <path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
                                        <path d="M8.7 10.7l6.6 -3.4"></path>
                                        <path d="M8.7 13.3l6.6 3.4"></path>
                                    </svg>
                                    <?= lang('theme_options.tab.social', [], 'Sosyal Medya') ?>
                                </a>
                                <a class="nav-link" id="v-pills-page-tab" data-bs-toggle="pill" href="#v-pills-page" role="tab" aria-controls="v-pills-page" aria-selected="false">
                                    <svg class="icon me-2" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                        <path d="M3 19a9 9 0 0 1 9 0a9 9 0  0 1 9 0"></path>
                                        <path d="M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0"></path>
                                        <path d="M3 6l0 13"></path>
                                        <path d="M12 6l0 13"></path>
                                        <path d="M21 6l0 13"></path>
                                    </svg>
                                    <?= lang('theme_options.tab.pages', [], 'Sayfa Ayarları') ?>
                                </a>
                                <a class="nav-link" id="v-pills-brand-tab" data-bs-toggle="pill" href="#v-pills-brand" role="tab" aria-controls="v-pills-brand" aria-selected="false">
                                    <i class="ri-image-add-fill" style="font-size:24px"></i>
                                    <?= lang('theme_options.tab.brands', [], 'Marka Logoları') ?>
                                </a>
                            </div>
                        </div><!-- end col -->
                        <div class="col-md-9">
                            <div class="tab-content text-muted mt-4 mt-md-0" id="v-pills-tabContent">
                                <div class="tab-pane fade show active" id="v-pills-general" role="tabpanel" aria-labelledby="v-pills-general-tab">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.color_scheme', [], 'Tema Renk Şeması') ?></label>
                                                <select class="form-select mb-3" name="color_scheme_<?=$lang?>">
                                                    <option <?php echo (theme_settings('color_scheme', $lang) == 'light') ? 'selected="selected"' : ''; ?> value="light"><?= lang('theme_options.color_scheme.light', [], 'Açık Tema') ?></option>
                                                    <option <?php echo (theme_settings('color_scheme', $lang) == 'dark') ? 'selected="selected"' : ''; ?> value="dark"><?= lang('theme_options.color_scheme.dark', [], 'Koyu Tema') ?></option>
                                                    <option <?php echo (theme_settings('color_scheme', $lang) == 'auto') ? 'selected="selected"' : ''; ?> value="auto"><?= lang('theme_options.color_scheme.auto', [], 'Otomatik') ?></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.primary_color', [], 'Ana Renk') ?></label>
                                                <input type="color" name="primary_color_<?=$lang?>"  class="form-control form-control-color" id="primary_color_<?=$lang?>"  value="<?=theme_settings('primary_color', $lang)?>"  title="<?= lang('theme_options.primary_color.pick', [], 'Ana renk seçin') ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.secondary_color', [], 'İkincil Renk') ?></label>
                                                <input type="color" name="secondary_color_<?=$lang?>"  class="form-control form-control-color" id="secondary_color_<?=$lang?>"  value="<?=theme_settings('secondary_color', $lang)?>"  title="<?= lang('theme_options.secondary_color.pick', [], 'İkincil renk seçin') ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.header_style', [], 'Header Stili') ?></label>
                                                <select class="form-select mb-3" name="header_style_<?=$lang?>">
                                                    <option <?php echo (theme_settings('header_style', $lang) == 'default') ? 'selected="selected"' : ''; ?> value="default"><?= lang('default', [], 'Varsayılan') ?></option>
                                                    <option <?php echo (theme_settings('header_style', $lang) == 'centered') ? 'selected="selected"' : ''; ?> value="centered"><?= lang('theme_options.header_style.centered', [], 'Ortalanmış') ?></option>
                                                    <option <?php echo (theme_settings('header_style', $lang) == 'minimal') ? 'selected="selected"' : ''; ?> value="minimal"><?= lang('theme_options.header_style.minimal', [], 'Minimal') ?></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.footer_style', [], 'Footer Stili') ?></label>
                                                <select class="form-select mb-3" name="footer_style_<?=$lang?>">
                                                    <option <?php echo (theme_settings('footer_style', $lang) == 'default') ? 'selected="selected"' : ''; ?> value="default"><?= lang('default', [], 'Varsayılan') ?></option>
                                                    <option <?php echo (theme_settings('footer_style', $lang) == 'minimal') ? 'selected="selected"' : ''; ?> value="minimal"><?= lang('theme_options.footer_style.minimal', [], 'Minimal') ?></option>
                                                    <option <?php echo (theme_settings('footer_style', $lang) == 'extended') ? 'selected="selected"' : ''; ?> value="extended"><?= lang('theme_options.footer_style.extended', [], 'Genişletilmiş') ?></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.animations', [], 'Animasyon Efektleri') ?></label>
                                                <select class="form-select mb-3" name="animations_<?=$lang?>">
                                                    <option <?php echo (theme_settings('animations', $lang) == 1) ? 'selected="selected"' : ''; ?> value="1"><?= lang('active', [], 'Aktif') ?></option>
                                                    <option <?php echo (theme_settings('animations', $lang) == 2) ? 'selected="selected"' : ''; ?> value="2"><?= lang('passive', [], 'Pasif') ?></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.custom_css', [], 'Özel CSS') ?></label>
                                                <textarea class="form-control input-group-flat" name="custom_css_<?=$lang?>" rows="5" placeholder="<?= lang('theme_options.custom_css.placeholder', [], 'Tema için özel CSS kodları...') ?>"><?=theme_settings('custom_css', $lang)?></textarea>
                                                <small class="form-text text-muted"><?= lang('theme_options.custom_css.note', [], 'Bu CSS kodları sadece bu tema için geçerli olacaktır.') ?></small>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label">Copyright</label>
                                                <input type="text" name="copyright_<?=$lang?>"  class="form-control input-group-flat" id="copyright_<?=$lang?>"  value="<?=theme_settings('copyright', $lang)?>"  placeholder="Copyright">
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label">Preloader</label>
                                                <select class="form-select mb-3" name="preloader_<?=$lang?>">
                                                    <option <?php echo (theme_settings('preloader', $lang) == 1) ? 'selected="selected"' : ''; ?> value="1"><?= lang('active', [], 'Aktif') ?></option>
                                                    <option <?php echo (theme_settings('preloader', $lang) == 2) ? 'selected="selected"' : ''; ?> value="2"><?= lang('passive', [], 'Pasif') ?></option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="v-pills-logo" role="tabpanel" aria-labelledby="v-pills-logo-tab">
                                    <div class="col_md_12">
                                        <div class="mb-3">
                                            <label for="title" class="form-label">Logo</label>
                                            <?php
                                            if (theme_settings('logo', $lang)){
                                                ?>
                                                <input type="hidden"  data-v-image name="logo_<?=$lang?>" id="logo" value="<?=theme_settings('logo', $lang)?>">
                                                <img data-v-image src="<?=DOMAIN?>/media<?=theme_settings('logo', $lang)?>" alt="" id="logo-thumb"  data-media-gallery data-target-input="#logo" data-target-thumb="#logo-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle" width="150px">
                                                <?php
                                            }else{
                                                ?>
                                                <input type="hidden"  data-v-image name="logo_<?=$lang?>" id="logo" value="">
                                                <img data-v-image src="<?=ADMIN_THEME_URL?>/assets/images/placeholder.svg" alt="" id="logo-thumb"  data-media-gallery data-target-input="#logo" data-target-thumb="#logo-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle" width="150px">
                                                <?php
                                            }
                                            ?>
                                            <div class="py-3 text-center" style="width: 250px">
                                                <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="#logo" data-target-thumb="#logo-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('logo')">
                                                        <i class="la la-times"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col_md_12">
                                        <div class="mb-3">
                                            <label for="title" class="form-label">Favicon</label>
                                            <?php
                                            if (theme_settings('favicon', $lang)){
                                                ?>
                                                <input type="hidden"  data-v-image name="favicon_<?=$lang?>" id="favicon" value="<?=theme_settings('favicon', $lang)?>">
                                                <img data-v-image src="<?=DOMAIN?>/media<?=theme_settings('favicon', $lang)?>" alt="" id="favicon-thumb"  data-media-gallery data-target-input="#favicon" data-target-thumb="#favicon-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle" width="150px">
                                                <?php
                                            }else{
                                                ?>
                                                <input type="hidden"  data-v-image name="favicon_<?=$lang?>" id="favicon" value="">
                                                <img data-v-image src="<?=ADMIN_THEME_URL?>/assets/images/placeholder.svg" alt="" id="favicon-thumb"  data-media-gallery data-target-input="#favicon" data-target-thumb="#favicon-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle" width="150px">
                                                <?php
                                            }
                                            ?>
                                            <div class="py-3 text-center" style="width: 250px">
                                                <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="#favicon" data-target-thumb="#favicon-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('favicon')">
                                                        <i class="la la-times"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="v-pills-social-links" role="tabpanel" aria-labelledby="v-pills-social-links-tab">
                                    <div class="col-md-12">
                                        <div class="mb-3 input-group-v ">
                                            <label for="title" class="form-label">Facebook</label>
                                            <input type="text" name="facebook_<?=$lang?>"  class="form-control input-group-flat" id="facebook_<?=$lang?>"  value="<?=theme_settings('facebook', $lang)?>"  placeholder="Facebook">
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="mb-3 input-group-v ">
                                            <label for="title" class="form-label">Twitter</label>
                                            <input type="text" name="twitter_<?=$lang?>"  class="form-control input-group-flat" id="twitter_<?=$lang?>"  value="<?=theme_settings('twitter', $lang)?>"  placeholder="Twitter">
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="mb-3 input-group-v ">
                                            <label for="title" class="form-label">Instagram</label>
                                            <input type="text" name="instagram_<?=$lang?>"  class="form-control input-group-flat" id="instagram_<?=$lang?>"  value="<?=theme_settings('instagram', $lang)?>"  placeholder="Instagram">
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="v-pills-page" role="tabpanel" aria-labelledby="v-pills-page-tab">
                                                                            <div class="col-md-12">
                                            <div class="mb-3 input-group-v ">
                                                <label for="title" class="form-label"><?= lang('theme_options.homepage', [], 'Ana Sayfa') ?></label>
                                                <select class="form-select mb-3" name="homepage_<?=$lang?>">
                                                    <?php
                                                    foreach (posts('data','pages',$lang) as $page){
                                                        $selected = (theme_settings('homepage', $lang) == $page['sef']) ? 'selected' : '';
                                                        ?>
                                                        <option <?=$selected?> value="<?=$page['sef']?>"><?=$page['title']?></option>
                                                        <?php
                                                        if (theme_settings('homepage', $lang) === null) {
                                                            echo '<option selected disabled hidden>'.lang('select_page', [], 'Sayfa Seçin').'</option>';
                                                        }
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                </div>
                                <div class="tab-pane fade" id="v-pills-brand" role="tabpanel" aria-labelledby="v-pills-brand-tab">
                                    <div class="col-md-12">
                                        <?php $brands = json_decode(theme_settings('brand', $lang));
                                                $number = 0;
                                        ?>
                                        <div id="imageRepeater">
                                            <?php foreach ($brands as $brand){
                                                if (!empty($brand)) {?>
                                                    <div class="image-item">
                                                        <label for="title" class="form-label"><?= lang('theme_options.brand_logo', [], 'Marka Logosu') ?></label>
                                                        <input type="hidden"  data-v-image name="brand[]" id="brand<?=$number?>" value="<?=$brand?>">
                                                        <img data-v-image src="<?=image($brand)?>" alt="" id="brand<?=$number?>-thumb"  data-media-gallery data-target-input="#brand<?=$number?>" data-target-thumb="#brand<?=$number?>-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle" width="150px">
                                                        <div class="py-3 text-center" style="width: 250px">
                                                            <div class="btn-group w-100">
                                                                <button type="button" class="setmedia btn btn-primary btn-icon btn-sm w-100" data-media-gallery data-target-input="#brand<?=$number?>" data-target-thumb="#brand<?=$number?>-thumb" data-type="single">
                                                                    <i class="la la-image la-lg"></i> <?=lang('set_media')?>
                                                                </button>
                                                                <button type="button" class="removeImageBtn btn btn-primary btn-icon btn-sm w-100" style="margin-left:10px ">
                                                                    <i class="la la-times"></i> <?=lang('remove')?>
                                                                </button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <?php $number++; }} ?>
                                            <div class="image-item">
                                                <label for="title" class="form-label"><?= lang('theme_options.brand_logo', [], 'Marka Logosu') ?></label>
                                                <input type="hidden"  data-v-image name="brand[]" id="brand" value="">
                                                <img data-v-image src="<?=ADMIN_THEME_URL?>/assets/images/placeholder.svg" alt="" id="brand-thumb"  data-media-gallery data-target-input="#brand" data-target-thumb="#brand-thumb" data-type="single" class="img-thumbnail border-0 p-0 bg-light-subtle" width="150px">
                                                <div class="py-3 text-center" style="width: 250px">
                                                    <div class="btn-group w-100">
                                                        <button type="button" class="setmedia btn btn-primary btn-icon btn-sm w-100" data-media-gallery data-target-input="#brand" data-target-thumb="#brand-thumb" data-type="single">
                                                            <i class="la la-image la-lg"></i> <?=lang('set_media')?>
                                                        </button>
                                                        <button type="button" class="removeImageBtn btn btn-primary btn-icon btn-sm w-100" style="margin-left:10px ">
                                                            <i class="la la-times"></i> <?=lang('remove')?>
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <button id="addImageButton" class=" btn btn-primary btn-icon btn-sm" style="width: 250px"><?= lang('theme_options.brand_logo.add', [], 'Yeni Logo Ekle') ?></button>
                                    </div>
                                </div>
                            </div>
                        </div><!--  end col -->
                    </div>
                    <div class="card card-body" style="float: right">
                        <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')?>
                            </button>
                        </div>
                    </div>
                </div><!-- end card-body -->
            </div>
        </form>
        <?php else: ?>
        <div class="alert alert-warning"><?= lang('security_violation', [], 'Bu işlem için yetkiniz yok.') ?></div>
        <?php endif; ?>
    </div>
</div>
