<?php

/**
 * BookiFlex Stripe Payment Extension
 *
 * @package    BookiFlex
 * @subpackage StripePayment
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */
declare (strict_types = 1);
namespace BookiFlex\Extensions\StripePayment\Admin;

use BookiFlex\Core\Admin\Field\SectionNotice;
use BookiFlex\Core\Contract\PluginInterface;
use BookiFlex\Core\Util\ProFeature;
use Carbon_Fields\Field;
defined( 'ABSPATH' ) || exit;
/**
 * Settings for Stripe payment gateway.
 */
class PaymentSettings {
    public const PUBLIC_KEY = 'bflex__stripe_gateway__publishable_key';

    public const TEST_PUBLIC_KEY = 'bflex__stripe_gateway__test_publishable_key';

    public const SECRET_KEY = 'bflex__stripe_gateway__secret_key';

    public const TEST_SECRET_KEY = 'bflex__stripe_gateway__test_secret_key';

    public const TEST_MODE = 'bflex__stripe_gateway__test_mode';

    public const WEBHOOK_SECRET_KEY = 'bflex__stripe_gateway__webhook_secret_key';

    public const PAYMENT_METHODS = 'bflex__stripe_gateway__payment_methods';

    private PluginInterface $plugin;

    public function __construct( $plugin ) {
        $this->plugin = $plugin;
    }

    public function __invoke() : array {
        $fields = [
            Field::make( 'separator', 'bflex__stripe_gateway__separator', __( 'Stripe gateway', 'bookiflex' ) ),
            SectionNotice::make( 'bflex__stripe_gateway__description', __( 'Connect your Stripe account to accept online card payments. Enter your API keys from the Stripe Dashboard and configure the payment mode.', 'bookiflex' ), 'https://bookiflex.com/support/knowledge-base/stripe-setup/?utm_source=plugin&utm_medium=stripe_gateway&utm_campaign=documentation' ),
            Field::make( 'select', self::TEST_MODE, __( 'Mode', 'bookiflex' ) )->set_autoload( true )->set_options( [
                'test'       => __( 'Test', 'bookiflex' ),
                'production' => __( 'Production', 'bookiflex' ),
            ] )->set_default_value( 'test' )->set_help_text( sprintf( '%s <a href="https://stripe.com/docs/testing" target="_blank">Stripe Docs → Testing</a>.', __( 'Select "Test" to use your test keys and process transactions in Stripe\'s sandbox environment. No real charges will be made. Learn more in', 'bookiflex' ) ) ),
            Field::make( 'text', self::PUBLIC_KEY, __( 'Publishable Key', 'bookiflex' ) )->set_conditional_logic( [[
                'field' => self::TEST_MODE,
                'value' => 'production',
            ]] )->set_width( 50 )->set_help_text( sprintf( '%s <a href="https://dashboard.stripe.com/apikeys">Stripe Dashboard → Developers → API keys</a>. %s: pk_live_…', __( 'Your <strong>Publishable Key</strong> from Stripe.<br/>You can find it in your', 'bookiflex' ), __( 'Example', 'bookiflex' ) ) )->set_autoload( true ),
            Field::make( 'text', self::SECRET_KEY, __( 'Secret Key', 'bookiflex' ) )->set_conditional_logic( [[
                'field' => self::TEST_MODE,
                'value' => 'production',
            ]] )->set_width( 50 )->set_help_text( sprintf( '%s <a href="https://dashboard.stripe.com/apikeys">Stripe Dashboard → Developers → API keys</a>. %s: sk_live_…', __( 'Your <strong>Secret Key</strong> from Stripe. Keep it private — never share it.<br/>Available in', 'bookiflex' ), __( 'Example', 'bookiflex' ) ) )->set_autoload( true ),
            Field::make( 'text', self::TEST_PUBLIC_KEY, __( 'Publishable Test Key', 'bookiflex' ) )->set_conditional_logic( [[
                'field' => self::TEST_MODE,
                'value' => 'test',
            ]] )->set_width( 50 )->set_help_text( sprintf( '%s <a href="https://dashboard.stripe.com/apikeys">Stripe Dashboard → Developers → API keys</a>. %s: pk_test_…', __( 'Your <strong>Publishable Test Key</strong> from Stripe. Use this for testing payments in sandbox mode.<br/>Found in', 'bookiflex' ), __( 'Example', 'bookiflex' ) ) )->set_autoload( true ),
            Field::make( 'text', self::TEST_SECRET_KEY, __( 'Secret Test Key', 'bookiflex' ) )->set_conditional_logic( [[
                'field' => self::TEST_MODE,
                'value' => 'test',
            ]] )->set_width( 50 )->set_help_text( sprintf( '%s <a href="https://dashboard.stripe.com/apikeys">Stripe Dashboard → Developers → API keys</a>. %s: sk_test_…', __( 'Your <strong>Secret Test Key</strong> from Stripe. Use this for testing payments in sandbox mode.<br/>Found in', 'bookiflex' ), __( 'Example', 'bookiflex' ) ) )->set_autoload( true )
        ];
        $fields = array_merge( $fields, $this->addNotice() );
        return $fields;
    }

    private function addNotice() : array {
        return [ProFeature::notice( 'pro_notice_stripe_gateway', __( 'Get more control over your payments with Stripe. Accept not only cards but also <strong>alternative payment methods</strong>. Securely <strong>authorize a payment without charging immediately</strong> — for example, capture card details at booking and charge later at check-in.', 'bookiflex' ) )];
    }

}
