<?php

function caffito_admin_font_css_base(): string
{
    $font_woff2 = get_template_directory_uri() . '/assets/fonts/YekanBakh-VF.woff2';
    return '
    @font-face{
        font-family:"YekanBakhVF";
        src: url("' . esc_url($font_woff2) . '") format("woff2");
        font-weight:100 900;
        font-display:swap;
    }

    html.wp-toolbar body,
    .wp-core-ui {
        font-family:"YekanBakhVF", sans-serif;
    }

    #wpadminbar .ab-item,
    #wpadminbar .ab-label {
        font-family:"YekanBakhVF", sans-serif;
    }

    #adminmenu a.menu-top .wp-menu-name,
    #adminmenu .wp-submenu a,
    #adminmenu .wp-submenu-head {
        font-family:"YekanBakhVF", sans-serif;
    }

    .wrap, .notice, .updated, .error,
    .components-button, .components-base-control__label,
    .button, .button-primary,
    .tablenav, .widefat, .wp-list-table,
    .media-modal, .media-frame,
    input, select, textarea {
        font-family:"YekanBakhVF", sans-serif;
    }

    h1, h2, h3, h4, h5, h6 {
        font-family:"YekanBakhVF", sans-serif !important;
    }
    ';
}

function caffito_front_adminbar_css(): string
{
    $font_woff2 = get_template_directory_uri() . '/assets/fonts/YekanBakh-VF.woff2';
    return '
    @font-face{
        font-family:"YekanBakhVF";
        src: url("' . esc_url($font_woff2) . '") format("woff2");
        font-weight:100 900;
        font-display:swap;
    }
    #wpadminbar .ab-item,
    #wpadminbar .ab-label,
    .elementor-edit-link-title {
        font-family:"YekanBakhVF", sans-serif !important;
    }';
}

function caffito_elementor_editor_text_css(): string {
    $font_woff2 = get_template_directory_uri() . '/assets/fonts/YekanBakh-VF.woff2';
    return '
    @font-face{
        font-family:"YekanBakhVF";
        src: url("'. esc_url($font_woff2) .'") format("woff2");
        font-weight:100 900;
        font-display:swap;
    }
    .elementor-panel,
    .elementor-panel .elementor-control-title,
    .elementor-panel .elementor-panel-heading,
    .elementor-panel .elementor-nerd-box-message,
    .elementor-panel .elementor-button,
    .elementor-panel input,
    .elementor-panel select,
    .elementor-panel textarea,
    .elementor-panel h1, .elementor-panel h2, .elementor-panel h3,
    .elementor-panel h4, .elementor-panel h5, .elementor-panel h6 {
        font-family:"YekanBakhVF", sans-serif !important;
    }

    .elementor-panel .title-wrapper,
    .elementor-panel .title,
    .elementor-panel .elementor-control .title,
    .elementor-panel .elementor-repeater-fields .title,
    .elementor-panel .elementor-repeater-fields .title-wrapper,
    .elementor-panel .elementor-section-title,
    .elementor-panel .elementor-control-section-title {
        font-family:"YekanBakhVF", sans-serif !important;
    }
    ';
}
add_action('admin_enqueue_scripts', function () {
    wp_register_style('caffito-admin-font', false);
    wp_enqueue_style('caffito-admin-font');
    wp_add_inline_style('caffito-admin-font', caffito_admin_font_css_base());
}, 99);

add_action('wp_enqueue_scripts', function () {
    if (is_user_logged_in() && is_admin_bar_showing()) {
        wp_register_style('caffito-frontend-adminbar-font', false);
        wp_enqueue_style('caffito-frontend-adminbar-font');
        wp_add_inline_style('caffito-frontend-adminbar-font', caffito_front_adminbar_css());
    }
}, 99);

add_action('elementor/editor/after_enqueue_styles', function () {
    wp_register_style('caffito-el-editor-font', false);
    wp_enqueue_style('caffito-el-editor-font');
    wp_add_inline_style('caffito-el-editor-font', caffito_elementor_editor_text_css());
});

?>