<?php

use Bookingor\Frontend\Controller\Category\CategoryControlFront;
use Bookingor\Helper\HelperControl;
use Bookingor\Frontend\Controller\Staff\StaffControlFront;
use Bookingor\Frontend\Controller\Service\ServiceControlFront;
use Bookingor\Frontend\Controller\Location\LocationControlFront;

// Exit if accessed directly
if (! defined('ABSPATH')) exit;

$column = get_option('bookingor_settings_staff_card_column', '3');
$gap_x = get_option('bookingor_settings_staff_cards_gap_x', '10');
$gap_y = get_option('bookingor_settings_staff_cards_gap_y', '10');
$img_radius = get_option('bookingor_settings_staff_image_radius', '56');
$img_border_size = get_option('bookingor_settings_staff_image_border_size', '1');
$img_border_color = get_option('bookingor_settings_staff_image_border_color', '#ffffff');
$img_width = get_option('bookingor_settings_staff_image_width', '140');
$img_height = get_option('bookingor_settings_staff_image_height', '140');
$bg_active = get_option('bookingor_settings_staff_bg_active', 'off');
$bg_color = get_option('bookingor_settings_staff_bg_color', '#ffffff');
$border_active_color = get_option('bookingor_settings_staff_border_active_color', '#7752DD');
$headings_font = get_option('bookingor_settings_fonts_headings');
?>
<style>
    #bookingor-design-staff {
        --bookingor-staff-column: <?php echo esc_attr($column); ?>;
        --bookingor-staff-gap-x: <?php echo esc_attr($gap_x); ?>px;
        --bookingor-staff-gap-y: <?php echo esc_attr($gap_y); ?>px;
        --bookingor-staff-img-radius: <?php echo esc_attr($img_radius); ?>px;
        --bookingor-staff-img-border-size: <?php echo esc_attr($img_border_size); ?>px;
        --bookingor-staff-img-border-color: <?php echo esc_attr($img_border_color); ?>;
        --bookingor-staff-img-width: <?php echo esc_attr($img_width); ?>px;
        --bookingor-staff-img-height: <?php echo esc_attr($img_height); ?>px;
        --bookingor-staff-bg-color: <?php echo ($bg_active === 'on') ? esc_attr($bg_color) : 'transparent'; ?>;
        --bookingor-staff-border-active-color: <?php echo esc_attr($border_active_color); ?>;
        <?php if (!empty($headings_font)) {
            $fontFamily = "Bookingor " . $headings_font . ', sans-serif';
            if ($headings_font === 'Bitter' || $headings_font === 'Carme') {
                $fontFamily = "Bookingor " . $headings_font . ", serif";
            }
        ?>--bookingor-heading-font-family: <?php echo esc_attr($fontFamily); ?>;
        <?php } ?>
        --bookingor-staff-phone-display: <?php echo get_option('bookingor_settings_staff_phone_show', 'on') === 'on' ? 'block' : 'none'; ?>;
        --bookingor-staff-email-display: <?php echo get_option('bookingor_settings_staff_email_show', 'on') === 'on' ? 'block' : 'none'; ?>;
        --bookingor-staff-tagline-display: <?php echo get_option('bookingor_settings_staff_tagline_show', 'on') === 'on' ? 'block' : 'none'; ?>;
        --bookingor-staff-location-display: <?php echo get_option('bookingor_settings_staff_location_show', 'on') === 'on' ? 'block' : 'none'; ?>;
        --bookingor-staff-about-display: <?php echo get_option('bookingor_settings_staff_about_show', 'on') === 'on' ? 'block' : 'none'; ?>;
    }

    #bookingor-design-staff .bookingor-staff-heading {
        <?php if (!empty($headings_font)) { ?>font-family: var(--bookingor-heading-font-family) !important;
        <?php } ?>
    }
    #bookingor-design-staff .staff-cl {
        display: var(--bookingor-staff-phone-display) !important;
    }
    #bookingor-design-staff .staff-email {
        display: var(--bookingor-staff-email-display) !important;
    }
    #bookingor-design-staff .staff-tagline {
        display: var(--bookingor-staff-tagline-display) !important;
    }
    #bookingor-design-staff .staff-location {
        display: var(--bookingor-staff-location-display) !important;
    }
    #bookingor-design-staff .staff-about {
        display: var(--bookingor-staff-about-display) !important;
    }
</style>
<div class="bookingor design-1" id="bookingor-design-staff" data-design-id="<?php echo isset($get_design_id) ? esc_attr($get_design_id) : ''; ?>">

    <div class="bookingor-container w-100 f-h bookingor-g-0 bookingor-flex flex-column">
        <div class="bookingor-loader-container">
            <div class="bookingor-d-flex align-items-center justify-content-center pt-3 pb-3">
                <div class="bookingor-loader">
                    <div class="bookingor-loader-wheel"></div>
                    <div class="bookingor-loader-text bookingor-d-flex"></div>
                </div>
            </div>
        </div>
        <form id="bkinz-booking-design-<?php echo isset($get_design_id) ? esc_attr($get_design_id) : ''; ?>" class="bookingor-flex flex-column h-100">
            <input type="hidden" id="get-design-type" name="get_design_type" value="<?php echo isset($get_design_id) ? esc_attr($get_design_id) : ''; ?>">
            <?php if (get_option("bookingor_settings_staff_active") === "on") { ?>
                <div id="main-book-staff" class="bookingor-category-active bookingor-ft flex-fill g-0 f-height bookingor-d-none">
                    <div class="row bookingor-g-0 f-height">
                        <div class="bookingor-col-md-12 bookingor-col-lg-12 bookingor-col-xl-12  bookingor-flex j-width bookingor-g-0 bookingor-flex j-width flex-column ">
                            <div class="card-body ">
                                <div class="sidebar_container bookingor-flex flex-column bookingor-pd-all ">
                                    <div class="select">
                                        <!-- <div id="employeeWarning" class="select_warning bookingor-d-none align-items-center justify-content-center">
                                            <span class="bookingor-flex align-items-center justify-content-center">!</span>
                                            <!?php esc_html_e("Please Select a ", "bookingor-pro"); ?><!?php echo esc_html(get_option('bookingor_settings_staff_name')); ?>
                                        </div> -->
                                        <!-- <div class="bookingor-flex align-items-center justify-content-between bookingor-heading-top">
                                            <div class="full-head-1 bookingor-staff-heading"><!?php echo esc_html(get_option('bookingor_settings_staff_name')); ?></div>
                                        </div> -->
                                        <div id="selectListEmployee-10" class="select-list-1">
                                            <ul class="emp-g bookingor-d-flex flex-wrap gap-x-10">
                                                <?php
                                                foreach (
                                                    StaffControlFront::$f_staff as $key =>
                                                    $value
                                                ) { ?>
                                                    <li data-select="select-shop" data-get-service-id="<?php echo esc_attr($value->service_get_id); ?>" data-location-id="<?php echo isset($value->location_get_id) ? esc_attr($value->location_get_id) : (isset($value->location_id) ? esc_attr($value->location_id) : ''); ?>" data-staff-id="<?php echo esc_attr($value->staff_id); ?>" class="bookingor-click-start-staff shop-list-1 bookingor-all-staff select_list no-shadow get_all_data">
                                                        <div class="bookingor-flex align-items-center">
                                                            <div class="right bookingor-flex justify-content-start flex-column">
                                                                <div class="user-avatar">
                                                                    <?php if ($value->staff_icon) { ?>
                                                                        <img class="memeber-ava" src="<?php echo esc_attr(wp_get_attachment_url($value->staff_icon));  ?>" alt="" />
                                                                    <?php } else { ?>
                                                                        <img class="memeber-ava" src="" data-avatar="<?php echo esc_attr($value->staff_first_name . " " . $value->staff_last_name); ?>" alt="" />
                                                                    <?php } ?>
                                                                </div>
                                                                <div class="staff-data">
                                                                    <div class="staff-name" data-staff-name="<?php echo esc_attr($value->staff_first_name . ' ' . $value->staff_last_name); ?>">
                                                                        <?php echo esc_html($value->staff_first_name . " " . $value->staff_last_name); ?></div>
                                                                    <div class="staff-de">
                                                                        <?php if (get_option('bookingor_settings_staff_phone_show', 'on') === 'on' && !empty($value->staff_phone)) { ?>
                                                                            <div class="staff-cl">
                                                                                <i class="bx bx-phone-call"></i>
                                                                                <span class="staff-cl"><?php echo esc_html($value->staff_phone); ?></span>
                                                                            </div>
                                                                        <?php } ?>
                                                                        <?php if (get_option('bookingor_settings_staff_email_show', 'on') === 'on' && !empty($value->staff_email)) { ?>
                                                                            <div class="staff-email">
                                                                                <i class="bx bx-envelope"></i>
                                                                                <span class="staff-email"><?php echo esc_html($value->staff_email); ?></span>
                                                                            </div>
                                                                        <?php } ?>
                                                                        <?php if (get_option('bookingor_settings_staff_tagline_show', 'on') === 'on' && !empty($value->staff_tag_line)) { ?>
                                                                            <div class="staff-tagline">
                                                                                <span class="staff-tagline"><?php echo esc_html($value->staff_tag_line); ?></span>
                                                                            </div>
                                                                        <?php } ?>
                                                                        <?php if (get_option('bookingor_settings_staff_location_show', 'on') === 'on') {
                                                                            $loc_address = '';
                                                                            if (!empty($value->staff_location)) {
                                                                                $loc_address = $value->staff_location;
                                                                            } elseif (!empty($value->location_get_id)) {
                                                                                global $wpdb;
                                                                                $loc_ids = array_map('intval', explode(',', $value->location_get_id));
                                                                                if (!empty($loc_ids)) {
                                                                                    $loc_id = $loc_ids[0];
                                                                                    $loc_address = $wpdb->get_var($wpdb->prepare("SELECT location_address FROM {$wpdb->prefix}bookingor_location WHERE location_id = %d", $loc_id));
                                                                                }
                                                                            }
                                                                            if (!empty($loc_address)) { ?>
                                                                                <div class="staff-location">
                                                                                    <i class="bx bx-map"></i>
                                                                                    <span class="staff-location"><?php echo esc_html($loc_address); ?></span>
                                                                                </div>
                                                                            <?php }
                                                                        } ?>
                                                                        <?php if (get_option('bookingor_settings_staff_about_show', 'on') === 'on' && !empty($value->staff_about)) { ?>
                                                                            <div class="staff-about">
                                                                                <span class="staff-about"><?php echo esc_html($value->staff_about); ?></span>
                                                                            </div>
                                                                        <?php } ?>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </li>
                                                <?php
                                                }
                                                ?>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>
                </div>
            <?php } ?>
        </form>
    </div>
</div>