<?php

use KimaAI\Helper;
use KimaAI\Admin\Integrations\IntegrationManager;

$kimaai_integration = KimaAI()->classes->get(IntegrationManager::class);

$kimaai_woocommerce = [
  'type' => 'object',
  'title' => __('WooCommerce', 'kimaai'),
  'link' => 'woocommerce',
  'pageTitle' => __('WooCommerce Integration', 'kimaai'),
  'pageDescription' => __('WooCommerce integration', 'kimaai'),
  'onlyPremium' => !Helper::isPremium(),
  'preview' => [
    'component' => 'PluginIntegration',
    'plugin' => $kimaai_integration->pluginStatus('woocommerce'),
    'width' => '500px',
  ],
  'sections' => [
    'general' => [
      'title' => __('General', 'kimaai'),
      'description' => __('Configure the general WooCommerce integration settings.', 'kimaai'),
    ],
  ],
  'properties' => [
    'isEnable' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'props' => [
        'label' => __('Enable', 'kimaai'),
        'checked' => false,
        'description' => __('Enable or disable the WooCommerce integration', 'kimaai'),
      ],
    ],
    'productDisplay' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'condition' => [
        'field' => 'isEnable',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Display product details', 'kimaai'),
        'checked' => false,
        'description' => __('Display product details with image and price in the chatbot widget', 'kimaai'),
      ],
    ],
    'productDisplayInstructions' => [
      'type' => 'string',
      'default' => "For product display requests: 
      \n 1. Use wc_get_product when the user asks for a specific product. 
      \n 2. Use only the returned WooCommerce product data. 
      \n 3. When product data is returned, the product card renderable can be shown automatically.",
      'sanitize_callback' => 'wp_kses_post',
      'validate_callback' => 'rest_validate_request_arg',
      'component' => 'TextareaField',
      'condition' => [
        'field' => 'productDisplay',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Product Display Instructions', 'kimaai'),
        'description' => __('Instructions for the AI on how to handle product display requests. 
        You can customize these instructions to guide the AI in fetching and displaying product information effectively.', 'kimaai'),
      ],
    ],
    'productRecemmendation' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'condition' => [
        'field' => 'isEnable',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Product Recommendations', 'kimaai'),
        'checked' => false,
        'description' => __('Enable product recommendation feature in the chatbot widget, allowing the AI to suggest relevant products based on user queries and interactions.', 'kimaai'),
      ],
    ],
    'productRecemmendationInstructions' => [
      'type' => 'string',
      'default' => "For product recommendation requests: 
      \n 1. Use wc_search_products to find the most relevant products. 
      \n 2. Use the returned product data to answer and recommend 2 to 6 products. 
      \n 3. Base your answer only on the returned WooCommerce product data.",
      'sanitize_callback' => 'wp_kses_post',
      'validate_callback' => 'rest_validate_request_arg',
      'component' => 'TextareaField',
      'condition' => [
        'field' => 'productRecemmendation',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Product Recommendation Instructions', 'kimaai'),
        'description' => __('Instructions for the AI on how to handle product recommendation requests. 
        Customize these instructions to guide the AI in suggesting relevant products effectively based on user queries and interactions.', 'kimaai'),
      ],
    ],
    'productSimilar' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'condition' => [
        'field' => 'isEnable',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Similar Products', 'kimaai'),
        'checked' => false,
        'description' => __('Enable similar product suggestions based on shared categories, tags, and attributes.', 'kimaai'),
      ],
    ],
    'productSimilarInstructions' => [
      'type' => 'string',
      'default' => "For similar product requests:
      \n 1. Use wc_get_similar_products when the user asks for products similar to a known product.
      \n 2. Similarity should be based on shared categories, tags, and attributes.
      \n 3. Recommend the most relevant 2 to 6 products from the tool result.",
      'sanitize_callback' => 'wp_kses_post',
      'validate_callback' => 'rest_validate_request_arg',
      'component' => 'TextareaField',
      'condition' => [
        'field' => 'productSimilar',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Similar Products Instructions', 'kimaai'),
        'description' => __('Instructions for the AI on how to handle similar product requests. 
        Customize these instructions to guide the AI in suggesting products that are similar to a known product based on shared categories, tags, and attributes effectively.', 'kimaai'),
      ],
    ],
  ],
];
$kimaai_gravityforms = [
  'type' => 'object',
  'title' => __('Gravity Forms', 'kimaai'),
  'link' => 'gravityforms',
  'pageTitle' => __('Gravity Forms Integration', 'kimaai'),
  'pageDescription' => __('Gravity Forms integration', 'kimaai'),
  'onlyPremium' => !Helper::isPremium(),
  'preview' => [
    'component' => 'PluginIntegration',
    // phpcs:ignore 'plugin' => $integration->pluginStatus('gravityforms'),
    'width' => '500px',
  ],
  'sections' => [
    'general' => [
      'title' => __('General', 'kimaai'),
      'description' => __('Configure the general Gravity Forms integration settings.', 'kimaai'),
    ],
  ],
  'properties' => [
    'isEnable' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'props' => [
        'label' => __('Enable', 'kimaai'),
        'checked' => false,
        'description' => __('Enable or disable the Gravity Forms integration', 'kimaai'),
      ],
    ],
    'formDisplay' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'condition' => [
        'field' => 'isEnable',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Render/Display form', 'kimaai'),
        'checked' => false,
        'description' => __('Render/display Gravity Forms forms in the chatbot widget when relevant', 'kimaai'),
      ],
    ],
  ],
];
$kimaai_contactform7 = [
  'type' => 'object',
  'title' => __('Contact Form 7', 'kimaai'),
  'link' => 'contactform7',
  'pageTitle' => __('Contact Form 7 Integration', 'kimaai'),
  'pageDescription' => __('Contact Form 7 integration', 'kimaai'),
  'onlyPremium' => !Helper::isPremium(),
  'preview' => [
    'component' => 'PluginIntegration',
    // phpcs:ignore 'plugin' => $integration->pluginStatus('contact-form-7'),
    'width' => '500px',
  ],
  'sections' => [
    'general' => [
      'title' => __('General', 'kimaai'),
      'description' => __('Configure the general Contact Form 7 integration settings.', 'kimaai'),
    ],
  ],
  'properties' => [
    'isEnable' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'props' => [
        'label' => __('Enable', 'kimaai'),
        'checked' => false,
        'description' => __('Enable or disable the Contact Form 7 integration', 'kimaai'),
      ],
    ],
    'contactform7Display' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'condition' => [
        'field' => 'isEnable',
        'operator' => '=',
        'value' => true,
      ],
      'props' => [
        'label' => __('Render/Display form', 'kimaai'),
        'checked' => false,
        'description' => __('Render/display Contact Form 7 forms in the chatbot widget when relevant', 'kimaai'),
      ],
    ],
  ],
];
$kimaai_elasticpress = [
  'type' => 'object',
  'title' => __('ElasticPress', 'kimaai'),
  'link' => 'elasticpress',
  'pageTitle' => __('ElasticPress Integration', 'kimaai'),
  'pageDescription' => __('ElasticPress integration', 'kimaai'),
  'onlyPremium' => !Helper::isPremium(),
  'preview' => [
    'component' => 'PluginIntegration',
    // phpcs:ignore 'plugin' => $integration->pluginStatus('elasticpress'),
    'width' => '500px',
  ],
  'properties' => [
    'isEnable' => [
      'type' => 'boolean',
      'default' => false,
      'component' => 'ToggleField',
      'props' => [
        'label' => __('Enable', 'kimaai'),
        'checked' => false,
        'description' => __('Enable or disable the ElasticPress integration', 'kimaai'),
      ],
    ],
  ],
];

$kimaai_properties = [
  'woocommerce' => $kimaai_woocommerce,
  // phpcs:ignore
  // 'gravityforms' => $gravityforms,
  // 'contactform7' => $contactform7,
  // 'elasticpress' => $elasticpress,
];

return [
  'order' => 9,
  'schema' => [
    'type' => 'object',
    'title' => __('Integrations', 'kimaai'),
    'icon' => 'plusCircle',
    'isOpen' => true,
    'properties' => $kimaai_properties,
  ],
];
