<?php echo message_box('success') ?>
<?php echo message_box('error') ?>

<?php
$logoicon = config_item('logo_or_icon');
$logo_options = array(
    'logo_title' => lang('logo') . ' & ' . lang('site_name'),
    'logo' => lang('logo'),
);

$active_pre_loader = config_item('active_pre_loader');
$preserved_settings = array(
    'sidebar_theme',
    'aside-float',
    'show-scrollbar',
    'aside-collapsed',
    'layout-h',
    'layout-boxed',
    'layout-fixed',
    'login_position',
    'RTL',
    'active_custom_color',
    'navbar_logo_background',
    'top_bar_background',
    'top_bar_color',
    'sidebar_background',
    'sidebar_color',
    'sidebar_active_background',
    'sidebar_active_color',
    'submenu_open_background',
    'active_background',
    'active_color',
    'body_background',
    'sidebar_font_size',
    'body_font_size',
);
?>

<div class="max-w-5xl">
    <form action="<?php echo base_url() ?>admin/settings/save_theme" enctype="multipart/form-data" method="post" class="space-y-5">
        <input type="hidden" name="settings" value="<?= $load_setting ?>">
        <?php foreach ($preserved_settings as $setting_key) : ?>
            <input type="hidden" name="<?= $setting_key ?>" value="<?= html_escape(config_item($setting_key)) ?>">
        <?php endforeach; ?>
        <input type="hidden" name="active_pre_loader" value="0">

        <div class="rounded-lg border border-border bg-card shadow-sm">
            <div class="flex flex-col gap-3 border-b border-border px-5 py-4 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <h3 class="text-lg font-semibold text-foreground"><?= lang('theme_settings') ?></h3>
                    <p class="text-sm text-muted-foreground"><?= lang('manage') . ' ' . lang('theme_settings') ?></p>
                </div>
                <button type="submit" class="inline-flex items-center justify-center gap-2 rounded-lg bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground shadow-sm transition-colors hover:bg-primary/90">
                    <i data-lucide="save" class="h-4 w-4"></i>
                    <?= lang('save_changes') ?>
                </button>
            </div>

            <div class="p-5">
                <section class="space-y-5">
                    <div class="space-y-1">
                        <div class="flex items-center gap-2">
                            <i data-lucide="badge" class="h-5 w-5 text-muted-foreground"></i>
                            <h4 class="text-base font-semibold text-foreground"><?= lang('branding') ?></h4>
                        </div>
                    </div>

                    <?= form_input_group('website_name', lang('site_name'), config_item('website_name')) ?>
                    <?= form_select_group('logo_or_icon', lang('logo'), $logo_options, $logoicon) ?>
                    <?= form_checkbox('active_pre_loader', lang('active_pre_loader'), !empty($active_pre_loader) && $active_pre_loader == 1, false, array('value' => 1)) ?>

                    <div class="grid grid-cols-1 gap-5 sm:grid-cols-2">
                        <div class="space-y-3">
                            <label class="text-sm font-medium text-foreground"><?= lang('company_logo') ?></label>
                            <div class="flex h-32 items-center justify-center overflow-hidden rounded-lg border border-border bg-muted/20">
                                <?php if (config_item('company_logo') != '') : ?>
                                    <img src="<?php echo base_url() . config_item('company_logo'); ?>" alt="<?= lang('company_logo') ?>" class="h-full w-full object-contain">
                                <?php else : ?>
                                    <img src="<?= base_url('uploads/default_avatar.jpg') ?>" alt="<?= lang('company_logo') ?>" class="h-full w-full object-contain">
                                <?php endif; ?>
                            </div>
                            <?= form_attachment_group('company_logo', '', 'photo', array(
                                'wrap' => false,
                                'select_label' => lang('choose_file'),
                                'remove_label' => lang('remove'),
                                'no_file_label' => lang('no_file_selected')
                            )) ?>
                            <div id="valid_msg_company_logo" class="text-xs text-destructive"></div>
                        </div>

                        <div class="space-y-3">
                            <label class="text-sm font-medium text-foreground"><?= lang('favicon') ?></label>
                            <div class="flex h-32 items-center justify-center overflow-hidden rounded-lg border border-border bg-muted/20">
                                <?php if (config_item('favicon') != '') : ?>
                                    <img src="<?php echo base_url() . config_item('favicon'); ?>" alt="<?= lang('favicon') ?>" class="h-full w-full object-contain">
                                <?php else : ?>
                                    <img src="<?= base_url('uploads/default_avatar.jpg') ?>" alt="<?= lang('favicon') ?>" class="h-full w-full object-contain">
                                <?php endif; ?>
                            </div>
                            <?= form_attachment_group('favicon', '', 'photo', array(
                                'wrap' => false,
                                'select_label' => lang('choose_file'),
                                'remove_label' => lang('remove'),
                                'no_file_label' => lang('no_file_selected')
                            )) ?>
                            <div id="valid_msg_favicon" class="text-xs text-destructive"></div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </form>
</div>
