<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
 *
 * Options Class
 *
 * @since 1.0.0
 * @version 1.0.0
 *
 */
use ThemeAtelier\DomainForSale\Admin\Framework\Classes\DOMAIN_FOR_SALE;

if ( ! class_exists( 'DOMAIN_FOR_SALE_Options' ) ) {
  class DOMAIN_FOR_SALE_Options extends DOMAIN_FOR_SALE_Abstract {

    // constans
    public $unique       = '';
    public $notice       = '';
    public $abstract     = 'options';
    public $sections     = array();
    public $options      = array();
    public $errors       = array();
    public $pre_tabs     = array();
    public $pre_fields   = array();
    public $pre_sections = array();
    public $args         = array(

      // framework title
      'framework_title'         => 'Codestar Framework <small>by Codestar</small>',
      'framework_class'         => '',

      // menu settings
      'menu_title'              => '',
      'menu_slug'               => '',
      'menu_type'               => 'menu',
      'menu_capability'         => 'manage_options',
      'menu_icon'               => null,
      'menu_position'           => null,
      'menu_hidden'             => false,
      'menu_parent'             => '',
      'sub_menu_title'          => '',

      // menu extras
      'show_bar_menu'           => true,
      'show_sub_menu'           => true,
      'show_in_network'         => true,
      'show_in_customizer'      => false,

      'show_search'             => true,
      'show_reset_all'          => true,
      'show_reset_section'      => true,
      'show_footer'             => true,
      'show_all_options'        => true,
      'show_form_warning'       => true,
      'sticky_header'           => true,
      'save_defaults'           => true,
      'ajax_save'               => true,
      'form_action'             => '',

      // admin bar menu settings
      'admin_bar_menu_icon'     => '',
      'admin_bar_menu_priority' => 50,

      // footer
      'footer_text'             => 'Thank you for creating with Codestar Framework',
      'footer_after'            => '',
      'footer_credit'           => '',

      // database model
      'database'                => '', // options, transient, theme_mod, network
      'transient_time'          => 0,

      // contextual help
      'contextual_help'         => array(),
      'contextual_help_sidebar' => '',

      // typography options
      'enqueue_webfont'         => true,
      'async_webfont'           => false,

      // others
      'output_css'              => true,

      // theme
      'nav'                     => 'normal',
      'theme'                   => 'dark',
      'class'                   => '',

      // external default values
      'defaults'                => array(),

    );

    // run framework construct
    public function __construct( $key, $params = array() ) {

      $this->unique   = $key;
      $this->args     = apply_filters( "DOMAIN_FOR_SALE_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
      $this->sections = apply_filters( "DOMAIN_FOR_SALE_{$this->unique}_sections", $params['sections'], $this );

      // run only is admin panel options, avoid performance loss
      $this->pre_tabs     = $this->pre_tabs( $this->sections );
      $this->pre_fields   = $this->pre_fields( $this->sections );
      $this->pre_sections = $this->pre_sections( $this->sections );

      $this->get_options();
      $this->set_options();
      $this->save_defaults();

      add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
      add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), $this->args['admin_bar_menu_priority'] );
      add_action( 'wp_ajax_DOMAIN_FOR_SALE_'. $this->unique .'_ajax_save', array( $this, 'ajax_save' ) );

      if ( $this->args['database'] === 'network' && ! empty( $this->args['show_in_network'] ) ) {
        add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) );
      }

      // wp enqeueu for typography and output css
      parent::__construct();

    }

    // instance
    public static function instance( $key, $params = array() ) {
      return new self( $key, $params );
    }

    // add admin bar menu
    public function add_admin_bar_menu( $wp_admin_bar ) {

      if ( ! current_user_can( $this->args['menu_capability'] ) ) {
        return;
      }

      if ( is_network_admin() && ( $this->args['database'] !== 'network' || $this->args['show_in_network'] !== true ) ) {
        return;
      }

      if ( ! empty( $this->args['show_bar_menu'] ) && empty( $this->args['menu_hidden'] ) ) {

        global $submenu;

        $menu_slug = $this->args['menu_slug'];
        $menu_icon = ( ! empty( $this->args['admin_bar_menu_icon'] ) ) ? '<span class="domain-for-sale-ab-icon ab-icon '. esc_attr( $this->args['admin_bar_menu_icon'] ) .'"></span>' : '';

        $wp_admin_bar->add_node( array(
          'id'    => $menu_slug,
          'title' => $menu_icon . esc_attr( $this->args['menu_title'] ),
          'href'  => esc_url( ( is_network_admin() ) ? network_admin_url( 'admin.php?page='. $menu_slug ) : admin_url( 'admin.php?page='. $menu_slug ) ),
        ) );

        if ( ! empty( $submenu[$menu_slug] ) ) {
          foreach ( $submenu[$menu_slug] as $menu_key => $menu_value ) {
            $wp_admin_bar->add_node( array(
              'parent' => $menu_slug,
              'id'     => $menu_slug .'-'. $menu_key,
              'title'  => $menu_value[0],
              'href'   => esc_url( ( is_network_admin() ) ? network_admin_url( 'admin.php?page='. $menu_value[2] ) : admin_url( 'admin.php?page='. $menu_value[2] ) ),
            ) );
          }
        }

      }

    }

    public function ajax_save() {

      $result = $this->set_options( true );

      if ( ! $result ) {
        wp_send_json_error( array( 'error' => esc_html__( 'Error while saving the changes.', 'domain-for-sale' ) ) );
      } else {
        wp_send_json_success( array( 'notice' => $this->notice, 'errors' => $this->errors ) );
      }

    }

    // get default value
    public function get_default( $field ) {

      $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
      $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;

      return $default;

    }

    // save defaults and set new fields value to main options
    public function save_defaults() {

      $tmp_options = $this->options;

      foreach ( $this->pre_fields as $field ) {
        if ( ! empty( $field['id'] ) ) {
          $this->options[$field['id']] = ( isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : $this->get_default( $field );
        }
      }

      if ( $this->args['save_defaults'] && empty( $tmp_options ) ) {
        $this->save_options( $this->options );
      }

    }

    // set options
    public function set_options( $ajax = false ) {

      // XSS ok.
      // No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341
      $response  = ( $ajax && ! empty( $_POST['data'] ) ) ? json_decode( wp_unslash( trim( $_POST['data'] ) ), true ) : $_POST;

      // Set variables.
      $data      = array();
      $noncekey  = 'DOMAIN_FOR_SALE_options_nonce'. $this->unique;
      $nonce     = ( ! empty( $response[$noncekey] ) ) ? $response[$noncekey] : '';
      $options   = ( ! empty( $response[$this->unique] ) ) ? $response[$this->unique] : array();
      $transient = ( ! empty( $response['DOMAIN_FOR_SALE_transient'] ) ) ? $response['DOMAIN_FOR_SALE_transient'] : array();

      if ( wp_verify_nonce( sanitize_text_field($nonce), 'DOMAIN_FOR_SALE_options_nonce' ) ) {

        $importing  = false;
        $section_id = ( ! empty( $transient['section'] ) ) ? $transient['section'] : '';

        if ( ! $ajax && ! empty( $response[ 'DOMAIN_FOR_SALE_import_data' ] ) ) {

          // XSS ok.
          // No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341
          $import_data  = json_decode( wp_unslash( trim( $response[ 'DOMAIN_FOR_SALE_import_data' ] ) ), true );
          $options      = ( is_array( $import_data ) && ! empty( $import_data ) ) ? $import_data : array();
          $importing    = true;
          $this->notice = esc_html__( 'Settings successfully imported.', 'domain-for-sale' );

        }

        if ( ! empty( $transient['reset'] ) ) {

          foreach ( $this->pre_fields as $field ) {
            if ( ! empty( $field['id'] ) ) {
              $data[$field['id']] = $this->get_default( $field );
            }
          }

          $this->notice = esc_html__( 'Default settings restored.', 'domain-for-sale' );

        } else if ( ! empty( $transient['reset_section'] ) && ! empty( $section_id ) ) {

          if ( ! empty( $this->pre_sections[$section_id-1]['fields'] ) ) {

            foreach ( $this->pre_sections[$section_id-1]['fields'] as $field ) {
              if ( ! empty( $field['id'] ) ) {
                $data[$field['id']] = $this->get_default( $field );
              }
            }

          }

          $data = wp_parse_args( $data, $this->options );

          $this->notice = esc_html__( 'Default settings restored.', 'domain-for-sale' );

        } else {

          // sanitize and validate
          foreach ( $this->pre_fields as $field ) {

            if ( ! empty( $field['id'] ) ) {

              $field_id    = $field['id'];
              $field_value = isset( $options[$field_id] ) ? $options[$field_id] : '';

              // Ajax and Importing doing wp_unslash already.
              if ( ! $ajax && ! $importing ) {
                $field_value = wp_unslash( $field_value );
              }

              // Sanitize "post" request of field.
              if ( ! isset( $field['sanitize'] ) ) {

                if( is_array( $field_value ) ) {

                  $data[$field_id] = wp_kses_post_deep( $field_value );

                } else {

                  $data[$field_id] = wp_kses_post( $field_value );

                }

              } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {

                $data[$field_id] = call_user_func( $field['sanitize'], $field_value );

              } else {

                $data[$field_id] = $field_value;

              }

              // Validate "post" request of field.
              if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {

                $has_validated = call_user_func( $field['validate'], $field_value );

                if ( ! empty( $has_validated ) ) {

                  $data[$field_id] = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';
                  $this->errors[$field_id] = $has_validated;

                }

              }

            }

          }

        }

        $data = apply_filters( "DOMAIN_FOR_SALE_{$this->unique}_save", $data, $this );

        do_action( "DOMAIN_FOR_SALE_{$this->unique}_save_before", $data, $this );

        $this->options = $data;

        $this->save_options( $data );

        do_action( "DOMAIN_FOR_SALE_{$this->unique}_save_after", $data, $this );

        if ( empty( $this->notice ) ) {
          $this->notice = esc_html__( 'Settings saved.', 'domain-for-sale' );
        }

        return true;

      }

      return false;

    }

    // save options database
    public function save_options( $data ) {

      if ( $this->args['database'] === 'transient' ) {
        set_transient( $this->unique, $data, $this->args['transient_time'] );
      } else if ( $this->args['database'] === 'theme_mod' ) {
        set_theme_mod( $this->unique, $data );
      } else if ( $this->args['database'] === 'network' ) {
        update_site_option( $this->unique, $data );
      } else {
        update_option( $this->unique, $data );
      }

      do_action( "DOMAIN_FOR_SALE_{$this->unique}_saved", $data, $this );

    }

    // get options from database
    public function get_options() {

      if ( $this->args['database'] === 'transient' ) {
        $this->options = get_transient( $this->unique );
      } else if ( $this->args['database'] === 'theme_mod' ) {
        $this->options = get_theme_mod( $this->unique );
      } else if ( $this->args['database'] === 'network' ) {
        $this->options = get_site_option( $this->unique );
      } else {
        $this->options = get_option( $this->unique );
      }

      if ( empty( $this->options ) ) {
        $this->options = array();
      }

      return $this->options;

    }

    // admin menu
    public function add_admin_menu() {

      extract( $this->args );

      if ( $menu_type === 'submenu' ) {

        $menu_page = call_user_func( 'add_submenu_page', $menu_parent, esc_attr( $menu_title ), esc_attr( $menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ) );

      } else {

        $menu_page = call_user_func( 'add_menu_page', esc_attr( $menu_title ), esc_attr( $menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ), $menu_icon, $menu_position );

        if ( ! empty( $sub_menu_title ) ) {
          call_user_func( 'add_submenu_page', $menu_slug, esc_attr( $sub_menu_title ), esc_attr( $sub_menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ) );
        }

        if ( ! empty( $this->args['show_sub_menu'] ) && count( $this->pre_tabs ) > 1 ) {

          // create submenus
          foreach ( $this->pre_tabs as $section ) {
            call_user_func( 'add_submenu_page', $menu_slug, esc_attr( $section['title'] ),  esc_attr( $section['title'] ), $menu_capability, $menu_slug .'#tab='. sanitize_title( $section['title'] ), '__return_null' );
          }

          remove_submenu_page( $menu_slug, $menu_slug );

        }

        if ( ! empty( $menu_hidden ) ) {
          remove_menu_page( $menu_slug );
        }

      }

      add_action( 'load-'. $menu_page, array( $this, 'add_page_on_load' ) );

    }

    public function add_page_on_load() {

      if ( ! empty( $this->args['contextual_help'] ) ) {

        $screen = get_current_screen();

        foreach ( $this->args['contextual_help'] as $tab ) {
          $screen->add_help_tab( $tab );
        }

        if ( ! empty( $this->args['contextual_help_sidebar'] ) ) {
          $screen->set_help_sidebar( $this->args['contextual_help_sidebar'] );
        }

      }

      if ( ! empty( $this->args['footer_credit'] ) ) {
        add_filter( 'admin_footer_text', array( $this, 'add_admin_footer_text' ) );
      }

    }

    public function add_admin_footer_text() {
      echo wp_kses_post( $this->args['footer_credit'] );
    }

    public function error_check( $sections, $err = '' ) {

      if ( ! $this->args['ajax_save'] ) {

        if ( ! empty( $sections['fields'] ) ) {
          foreach ( $sections['fields'] as $field ) {
            if ( ! empty( $field['id'] ) ) {
              if ( array_key_exists( $field['id'], $this->errors ) ) {
                $err = '<span class="domain-for-sale-label-error">!</span>';
              }
            }
          }
        }

        if ( ! empty( $sections['subs'] ) ) {
          foreach ( $sections['subs'] as $sub ) {
            $err = $this->error_check( $sub, $err );
          }
        }

        if ( ! empty( $sections['id'] ) && array_key_exists( $sections['id'], $this->errors ) ) {
          $err = $this->errors[$sections['id']];
        }

      }

      return $err;
    }

    // option page html output
    public function add_options_html() {

      $has_nav       = ( count( $this->pre_tabs ) > 1 ) ? true : false;
      $show_all      = ( ! $has_nav ) ? ' domain-for-sale-show-all' : '';
      $menu_slug     = isset($this->args['menu_slug']) ? $this->args['menu_slug'] : '';
      $ajax_class    = ( $this->args['ajax_save'] ) ? ' domain-for-sale-save-ajax' : '';
      $sticky_class  = ( $this->args['sticky_header'] ) ? ' domain-for-sale-sticky-header' : '';
      $wrapper_class = ( $this->args['framework_class'] ) ? ' '. $this->args['framework_class'] : '';
      $theme         = ( $this->args['theme'] ) ? ' domain-for-sale-theme-'. $this->args['theme'] : '';
      $class         = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
      $nav_type      = ( $this->args['nav'] === 'inline' ) ? 'inline' : 'normal';
      $form_action   = ( $this->args['form_action'] ) ? $this->args['form_action'] : '';

      do_action( 'DOMAIN_FOR_SALE_options_before' );

      echo '<div class="DOMAIN_FOR_SALE domain-for-sale-options'. esc_attr( $theme . $class . $wrapper_class ) .'" data-slug="'. esc_attr( $this->args['menu_slug'] ) .'" data-unique="'. esc_attr( $this->unique ) .'">';

        echo '<div class="domain-for-sale-container">';

        echo '<form method="post" action="'. esc_attr( $form_action ) .'" enctype="multipart/form-data" id="domain-for-sale-form" autocomplete="off" novalidate="novalidate">';

        echo '<input type="hidden" class="domain-for-sale-section-id" name="DOMAIN_FOR_SALE_transient[section]" value="1">';

        wp_nonce_field( 'DOMAIN_FOR_SALE_options_nonce', 'DOMAIN_FOR_SALE_options_nonce'. $this->unique );

        echo '<div class="domain-for-sale-header'. esc_attr( $sticky_class ) .'">';
        echo '<div class="domain-for-sale-header-inner">';
          echo '<div class="domain-for-sale-header-left">';
          if ($menu_slug === 'domain-for-sale-tools') {
        echo '<h1><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><path d="M566.6 470.6L470.6 566.6C461.4 575.8 447.7 578.5 435.7 573.5C423.7 568.5 416 556.9 416 544L416 480L96 480C78.3 480 64 465.7 64 448C64 430.3 78.3 416 96 416L416 416L416 352C416 339.1 423.8 327.4 435.8 322.4C447.8 317.4 461.5 320.2 470.7 329.3L566.7 425.3C579.2 437.8 579.2 458.1 566.7 470.6zM73.4 214.6C60.9 202.1 60.9 181.8 73.4 169.3L169.4 73.3C178.6 64.1 192.3 61.4 204.3 66.4C216.3 71.4 224 83.1 224 96L224 160L544 160C561.7 160 576 174.3 576 192C576 209.7 561.7 224 544 224L224 224L224 288C224 300.9 216.2 312.6 204.2 317.6C192.2 322.6 178.5 319.8 169.3 310.7L73.3 214.7z"/></svg>' . wp_kses_post($this->args['framework_title']) . '</h1>';
      } else {
        echo '<h1><svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
              <rect width="256" height="256" rx="3" fill="#014477"/>
              <path d="M100.466 91.6875H100.059C98.5662 91.6875 97.2417 92.6443 96.7724 94.0609L90.4097 113.263L84.0178 94.0567C83.5463 92.6417 82.2229 91.6875 80.7318 91.6875H80.1457C78.6524 91.6875 77.328 92.6443 76.8586 94.0609L70.496 113.263L64.104 94.0567C63.6325 92.6417 62.3092 91.6875 60.818 91.6875H60.411C59.2943 91.6875 58.2464 92.2256 57.5965 93.1329C56.9465 94.0401 56.7733 95.2058 57.1314 96.2628L66.951 125.221C67.4268 126.625 68.7459 127.57 70.2296 127.57H70.4566C70.472 127.57 70.488 127.568 70.5034 127.567C70.5189 127.568 70.5349 127.57 70.5503 127.57H70.7336C72.2194 127.57 73.5412 126.622 74.0153 125.213L80.4531 106.098L86.8605 125.208C87.3341 126.617 88.6554 127.57 90.1444 127.57H90.3703C90.3858 127.57 90.4017 127.568 90.4172 127.567C90.4326 127.568 90.4486 127.57 90.4641 127.57H90.6473C92.1311 127.57 93.4507 126.625 93.927 125.221L103.746 96.2628C104.105 95.2058 103.932 94.0401 103.282 93.1329C102.631 92.2256 101.583 91.6875 100.466 91.6875Z" fill="white"/>
              <path d="M148.497 91.6875H148.09C146.596 91.6875 145.273 92.6443 144.803 94.0609L138.441 113.263L132.048 94.0567C131.577 92.6417 130.253 91.6875 128.762 91.6875H128.176C126.683 91.6875 125.358 92.6443 124.889 94.0609L118.526 113.263L112.134 94.0567C111.663 92.6417 110.339 91.6875 108.848 91.6875H108.441C107.325 91.6875 106.277 92.2256 105.627 93.1329C104.977 94.0401 104.804 95.2058 105.162 96.2628L114.981 125.221C115.457 126.625 116.776 127.57 118.26 127.57H118.487C118.502 127.57 118.518 127.568 118.534 127.567C118.549 127.568 118.565 127.57 118.581 127.57H118.764C120.25 127.57 121.571 126.622 122.046 125.213L128.483 106.098L134.891 125.208C135.364 126.617 136.686 127.57 138.175 127.57H138.402C138.417 127.57 138.433 127.568 138.449 127.567C138.463 127.568 138.48 127.57 138.495 127.57H138.679C140.162 127.57 141.482 126.625 141.958 125.221L151.777 96.2628C152.136 95.2058 151.964 94.0401 151.313 93.1329C150.662 92.2256 149.613 91.6875 148.497 91.6875Z" fill="white"/>
              <path d="M196.529 91.6875H196.12C194.627 91.6875 193.304 92.6443 192.833 94.0609L186.472 113.263L180.08 94.0567C179.608 92.6417 178.285 91.6875 176.794 91.6875H176.207C174.713 91.6875 173.389 92.6443 172.92 94.0609L166.558 113.263L160.166 94.0567C159.694 92.6417 158.371 91.6875 156.88 91.6875H156.473C155.355 91.6875 154.308 92.2256 153.658 93.1329C153.008 94.0401 152.835 95.2058 153.193 96.2628L163.013 125.221C163.489 126.625 164.808 127.57 166.292 127.57H166.519C166.534 127.57 166.551 127.568 166.565 127.567C166.581 127.568 166.597 127.57 166.613 127.57H166.796C168.282 127.57 169.604 126.622 170.078 125.213L176.516 106.098L182.923 125.208C183.397 126.617 184.717 127.57 186.206 127.57H186.432C186.448 127.57 186.464 127.568 186.48 127.567C186.495 127.568 186.511 127.57 186.527 127.57H186.71C188.194 127.57 189.513 126.625 189.99 125.221L199.808 96.2628C200.167 95.2058 199.995 94.0401 199.344 93.1329C198.693 92.2256 197.645 91.6875 196.529 91.6875Z" fill="white"/>
              <path d="M39.0678 207.743V77.902H217.871L217.992 143.449C221.579 140.366 228.16 144.449 232.939 144.449C232.939 140.973 232.939 139.949 232.939 139.949V45.5559C232.939 38.6323 227.307 33 220.386 33H36.5559C29.6312 33 24 38.6323 24 45.5559V210.255C24 217.177 29.6312 222.811 36.5559 222.811H156.344C153.452 218.273 147.101 213.394 146 207.949L39.0678 207.743ZM204.084 54.0842C204.084 51.5233 206.159 49.4477 208.72 49.4477H213.356C215.917 49.4477 217.992 51.5233 217.992 54.0842V59.3387C217.992 61.8986 215.916 63.9742 213.356 63.9742H208.72C206.158 63.9742 204.084 61.8986 204.084 59.3387V54.0842ZM182.526 54.0842C182.526 51.5233 184.602 49.4477 187.162 49.4477H191.798C194.36 49.4477 196.434 51.5233 196.434 54.0842V59.3387C196.434 61.8986 194.358 63.9742 191.798 63.9742H187.162C184.602 63.9742 182.526 61.8986 182.526 59.3387V54.0842ZM160.967 54.0842C160.967 51.5233 163.043 49.4477 165.604 49.4477H170.239C172.799 49.4477 174.875 51.5233 174.875 54.0842V59.3387C174.875 61.8986 172.799 63.9742 170.239 63.9742H165.604C163.043 63.9742 160.967 61.8986 160.967 59.3387V54.0842Z" fill="white"/>
              <path d="M232.727 163.938C232.727 161.495 231.776 159.199 230.048 157.47L223.205 150.627C221.478 148.9 219.181 147.949 216.739 147.949C214.297 147.949 211.999 148.9 210.271 150.628L199.827 161.07C194.25 157.072 187.412 154.716 180.026 154.716C161.234 154.716 146 169.95 146 188.742C146 207.532 161.234 222.767 180.026 222.767C198.817 222.767 214.051 207.531 214.051 188.742C214.051 187.979 214.023 187.224 213.973 186.475L230.044 170.404C231.775 168.678 232.727 166.38 232.727 163.938ZM222.621 165.971L189.896 198.697C189.206 199.387 188.27 199.774 187.295 199.774H187.294C186.317 199.774 185.383 199.385 184.693 198.697L169.527 183.508C168.094 182.072 168.095 179.744 169.53 178.309L172.449 175.39C173.884 173.955 176.21 173.954 177.646 175.386L187.291 185.006L214.473 157.825C215.162 157.135 216.098 156.749 217.073 156.749C218.048 156.749 218.983 157.137 219.673 157.825L222.619 160.772C224.057 162.208 224.057 164.535 222.621 165.971Z" fill="white"/>
              <path d="M117.625 199.605H61.375C57.4914 199.605 54.3438 196.455 54.3438 192.574V159.762C54.3438 155.878 57.4914 152.73 61.375 152.73H66.0625L85.968 137.454C85.8789 137.091 85.818 136.716 85.818 136.324C85.818 133.737 87.918 131.637 90.5055 131.637C93.093 131.637 95.1906 133.737 95.1906 136.324C95.1906 137.166 94.9516 137.946 94.5602 138.63L112.938 152.73H117.625C121.506 152.73 124.656 155.878 124.656 159.762V192.574C124.656 196.455 121.506 199.605 117.625 199.605ZM92.0102 184.566H101.458V182.789H94.0047V169.458H92.0078L92.0102 184.566ZM78.4914 184.566L80.1461 179.988H86.493L88.232 184.566H90.5102L84.3508 169.46H82.1852L76.3773 184.566H78.4914ZM64.5203 171.232C64.0891 171.898 63.8734 172.613 63.8734 173.374C63.8734 174.07 64.0492 174.696 64.4031 175.259C64.757 175.821 65.2937 176.288 66.0133 176.67C66.5664 176.965 67.5344 177.279 68.9172 177.612C70.3 177.945 71.193 178.191 71.5984 178.348C72.2289 178.591 72.6812 178.884 72.9602 179.238C73.2391 179.592 73.3797 180.002 73.3797 180.476C73.3797 180.94 73.2367 181.373 72.9531 181.77C72.6695 182.166 72.2359 182.477 71.6523 182.705C71.0711 182.934 70.4008 183.047 69.6414 183.047C68.7859 183.047 68.0172 182.899 67.3328 182.597C66.6461 182.299 66.1422 181.905 65.8187 181.418C65.4953 180.93 65.2844 180.307 65.1953 179.55L63.3086 179.714C63.3367 180.724 63.6133 181.627 64.1383 182.426C64.6633 183.225 65.3852 183.827 66.3063 184.226C67.2297 184.624 68.3711 184.823 69.7352 184.823C70.8086 184.823 71.7766 184.627 72.6367 184.23C73.4969 183.837 74.1555 183.288 74.6148 182.576C75.0742 181.863 75.3039 181.111 75.3039 180.307C75.3039 179.498 75.093 178.786 74.6734 178.165C74.2539 177.544 73.6047 177.03 72.7234 176.627C72.1164 176.353 71.0055 176.032 69.3883 175.666C67.7688 175.298 66.768 174.938 66.3859 174.586C65.9945 174.239 65.8 173.791 65.8 173.25C65.8 172.622 66.0766 172.09 66.6273 171.647C67.1781 171.204 68.0547 170.981 69.2594 170.981C70.4172 170.981 71.2914 171.225 71.882 171.708C72.475 172.193 72.8195 172.91 72.9227 173.857L74.8445 173.712C74.8094 172.826 74.5633 172.034 74.1063 171.335C73.6492 170.637 72.9906 170.107 72.1375 169.746C71.2844 169.385 70.3 169.207 69.182 169.207C68.1672 169.207 67.2461 169.378 66.4164 169.723C65.582 170.065 64.9516 170.566 64.5203 171.232ZM93.4328 139.957C92.6266 140.606 91.6188 141.012 90.5055 141.012C88.9539 141.012 87.5898 140.25 86.7367 139.087L68.4062 152.73H110.594L93.4328 139.957ZM115.131 182.789H105.866V177.645H114.215V175.868H105.866V171.234H114.784V169.458H103.872V184.563H115.134L115.131 182.789ZM83.2047 171.035C83.4484 171.862 83.8047 172.91 84.2758 174.183L85.8672 178.359H80.7133L82.3891 173.937C82.7336 172.983 83.0055 172.015 83.2047 171.035Z" fill="white"/>
              </svg>' . wp_kses_post($this->args['framework_title']) . '</h1>';
      }
          echo '</div>';

          echo '<div class="domain-for-sale-header-right">';
            $notice_class = ( ! empty( $this->notice ) ) ? 'domain-for-sale-form-show' : '';
            $notice_text  = ( ! empty( $this->notice ) ) ? $this->notice : '';

            echo '<div class="domain-for-sale-form-result domain-for-sale-form-success '. esc_attr( $notice_class ) .'">'. wp_kses_post($notice_text) .'</div>';

            echo ( $this->args['show_form_warning'] ) ? '<div class="domain-for-sale-form-result domain-for-sale-form-warning">'. esc_html__( 'You have unsaved changes, save your changes!', 'domain-for-sale' ) .'</div>' : '';

            echo ( $has_nav && $this->args['show_all_options'] ) ? '<div class="domain-for-sale-expand-all" title="'. esc_html__( 'show all settings', 'domain-for-sale' ) .'"><i class="icofont-outdent"></i></div>' : '';

            echo ( $this->args['show_search'] ) ? '<div class="domain-for-sale-search"><input type="text" name="domain-for-sale-search" placeholder="'. esc_html__( 'Search...', 'domain-for-sale' ) .'" autocomplete="off" /></div>' : '';

            echo '<div class="domain-for-sale-buttons">';
            echo '<input type="submit" name="'. esc_attr( $this->unique ) .'[_nonce][save]" class="button button-primary domain-for-sale-top-save domain-for-sale-save'. esc_attr( $ajax_class ) .'" value="'. esc_html__( 'Save', 'domain-for-sale' ) .'" data-save="'. esc_html__( 'Saving...', 'domain-for-sale' ) .'">';
            echo ( $this->args['show_reset_section'] ) ? '<input type="submit" name="DOMAIN_FOR_SALE_transient[reset_section]" class="button button-secondary domain-for-sale-reset-section domain-for-sale-confirm" value="'. esc_html__( 'Reset Section', 'domain-for-sale' ) .'" data-confirm="'. esc_html__( 'Are you sure to reset this section options?', 'domain-for-sale' ) .'">' : '';
            echo ( $this->args['show_reset_all'] ) ? '<input type="submit" name="DOMAIN_FOR_SALE_transient[reset]" class="button domain-for-sale-warning-primary domain-for-sale-reset-all domain-for-sale-confirm" value="'. ( ( $this->args['show_reset_section'] ) ? esc_html__( 'Reset All', 'domain-for-sale' ) : esc_html__( 'Reset', 'domain-for-sale' ) ) .'" data-confirm="'. esc_html__( 'Are you sure you want to reset all settings to default values?', 'domain-for-sale' ) .'">' : '';
            echo '</div>';

          echo '</div>';

          echo '<div class="clear"></div>';
          echo '</div>';
        echo '</div>';

        echo '<div class="domain-for-sale-wrapper'. esc_attr( $show_all ) .'">';

          if ( $has_nav ) {

            echo '<div class="domain-for-sale-nav domain-for-sale-nav-'. esc_attr( $nav_type ) .' domain-for-sale-nav-options">';

              echo '<ul>';

              foreach ( $this->pre_tabs as $tab ) {

                $tab_id    = sanitize_title( $tab['title'] );
                $tab_error = $this->error_check( $tab );
                $tab_icon  = ( ! empty( $tab['icon'] ) ) ? '<i class="domain-for-sale-tab-icon '. esc_attr( $tab['icon'] ) .'"></i>' : '';

                if ( ! empty( $tab['subs'] ) ) {

                  echo '<li class="domain-for-sale-tab-item">';

                    echo '<a href="#tab='. esc_attr( $tab_id ) .'" data-tab-id="'. esc_attr( $tab_id ) .'" class="domain-for-sale-arrow">'. wp_kses_post($tab_icon) . wp_kses_post($tab['title']) . wp_kses_post($tab_error) .'</a>';

                    echo '<ul>';

                    foreach ( $tab['subs'] as $sub ) {

                      $sub_id    = $tab_id .'/'. sanitize_title( $sub['title'] );
                      $sub_error = $this->error_check( $sub );
                      $sub_icon  = ( ! empty( $sub['icon'] ) ) ? '<i class="domain-for-sale-tab-icon '. esc_attr( $sub['icon'] ) .'"></i>' : '';

                      echo '<li><a href="#tab='. esc_attr( $sub_id ) .'" data-tab-id="'. esc_attr( $sub_id ) .'">'. wp_kses_post($sub_icon . $sub['title'] . $sub_error) .'</a></li>';

                    }

                    echo '</ul>';

                  echo '</li>';

                } else {

                  echo '<li class="domain-for-sale-tab-item"><a href="#tab='. esc_attr( $tab_id ) .'" data-tab-id="'. esc_attr( $tab_id ) .'">'. wp_kses_post($tab_icon . $tab['title'] . $tab_error) .'</a></li>';

                }

              }

              echo '</ul>';

            echo '</div>';

          }

          echo '<div class="domain-for-sale-content">';

            echo '<div class="domain-for-sale-sections">';

            foreach ( $this->pre_sections as $section ) {

              $section_onload = ( ! $has_nav ) ? ' domain-for-sale-onload' : '';
              $section_class  = ( ! empty( $section['class'] ) ) ? ' '. $section['class'] : '';
              $section_icon   = ( ! empty( $section['icon'] ) ) ? '<i class="domain-for-sale-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
              $section_title  = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
              $section_parent = ( ! empty( $section['ptitle'] ) ) ? sanitize_title( $section['ptitle'] ) .'/' : '';
              $section_slug   = ( ! empty( $section['title'] ) ) ? sanitize_title( $section_title ) : '';

              echo '<div class="domain-for-sale-section hidden'. esc_attr( $section_onload . $section_class ) .'" data-section-id="'. esc_attr( $section_parent . $section_slug ) .'">';
              echo ( $has_nav ) ? '<div class="domain-for-sale-section-title"><h3>'. wp_kses_post($section_icon . $section_title) .'</h3></div>' : '';
              echo ( ! empty( $section['description'] ) ) ? '<div class="domain-for-sale-field domain-for-sale-section-description">'. wp_kses_post($section['description']) .'</div>' : '';

              if ( ! empty( $section['fields'] ) ) {

                foreach ( $section['fields'] as $field ) {

                  $is_field_error = $this->error_check( $field );

                  if ( ! empty( $is_field_error ) ) {
                    $field['_error'] = $is_field_error;
                  }

                  if ( ! empty( $field['id'] ) ) {
                    $field['default'] = $this->get_default( $field );
                  }

                  $value = ( ! empty( $field['id'] ) && isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : '';

                  DOMAIN_FOR_SALE::field( $field, $value, $this->unique, 'options' );

                }

              } else {

                echo '<div class="domain-for-sale-no-option">'. esc_html__( 'No data available.', 'domain-for-sale' ) .'</div>';

              }

              echo '</div>';

            }

            echo '</div>';

            echo '<div class="clear"></div>';

          echo '</div>';

          echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="domain-for-sale-nav-background"></div>' : '';

        echo '</div>';

        if ( ! empty( $this->args['show_footer'] ) ) {

          echo '<div class="domain-for-sale-footer">';

          echo '<div class="domain-for-sale-buttons">';
          echo '<input type="submit" name="DOMAIN_FOR_SALE_transient[save]" class="button button-primary domain-for-sale-save'. esc_attr( $ajax_class ) .'" value="'. esc_html__( 'Save', 'domain-for-sale' ) .'" data-save="'. esc_html__( 'Saving...', 'domain-for-sale' ) .'">';
          echo ( $this->args['show_reset_section'] ) ? '<input type="submit" name="DOMAIN_FOR_SALE_transient[reset_section]" class="button button-secondary domain-for-sale-reset-section domain-for-sale-confirm" value="'. esc_html__( 'Reset Section', 'domain-for-sale' ) .'" data-confirm="'. esc_html__( 'Are you sure to reset this section options?', 'domain-for-sale' ) .'">' : '';
          echo ( $this->args['show_reset_all'] ) ? '<input type="submit" name="DOMAIN_FOR_SALE_transient[reset]" class="button domain-for-sale-warning-primary domain-for-sale-reset-all domain-for-sale-confirm" value="'. ( ( $this->args['show_reset_section'] ) ? esc_html__( 'Reset All', 'domain-for-sale' ) : esc_html__( 'Reset', 'domain-for-sale' ) ) .'" data-confirm="'. esc_html__( 'Are you sure you want to reset all settings to default values?', 'domain-for-sale' ) .'">' : '';
          echo '</div>';

          echo ( ! empty( $this->args['footer_text'] ) ) ? '<div class="domain-for-sale-copyright">'. wp_kses_post($this->args['footer_text']) .'</div>' : '';

          echo '<div class="clear"></div>';
          echo '</div>';

        }

        echo '</form>';

        echo '</div>';

        echo '<div class="clear"></div>';

        echo ( ! empty( $this->args['footer_after'] ) ) ? wp_kses_post($this->args['footer_after']) : '';

      echo '</div>';

      do_action( 'DOMAIN_FOR_SALE_options_after' );

    }
  }
}
