<?php
// @future: When features grow, convert sections to vtabs:
//   [vtab] General      - enable, button label
//   [vtab] My Account   - endpoint config, saved carts page
//   [vtab] Notifications (pro) - email on restore
//   [vtab] Cart Merge (pro)    - behavior when restoring into non-empty cart

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$settings = \Lex\Settings\V2\Settings::getInstance( 'lean_csns' );
$sr       = $settings->sectionRenderer;

$defaults      = [];
$defaults_file = dirname( __DIR__ ) . '/default-settings.php';
if ( file_exists( $defaults_file ) ) {
	$loaded = include $defaults_file;
	if ( is_array( $loaded ) ) {
		$defaults = $loaded;
	}
}

// ============================================
// SECTION: Save Cart Settings
// ============================================
$sr->startSection( 'cart_save_settings', esc_html__( 'Save Cart Settings', 'lean-cart-share-and-save' ) );

$settings->fieldRenderer->render( 'checkbox', 'cart_save.enable', [
	'label'          => esc_html__( 'Enable Save Cart', 'lean-cart-share-and-save' ),
	'checkbox_label' => esc_html__( 'Yes', 'lean-cart-share-and-save' ),
	'desc'           => esc_html__( 'Allow logged-in users to save their cart for later', 'lean-cart-share-and-save' ),
	'default'        => $defaults['cart_save']['enable'] ?? '1',
] );

$settings->fieldRenderer->render( 'text', 'cart_save.save_button_label', [
	'label'       => esc_html__( 'Save Button Label', 'lean-cart-share-and-save' ),
	'desc'        => esc_html__( 'Customize the text shown on the Save Cart button. Leave empty to use the default.', 'lean-cart-share-and-save' ),
	'placeholder' => esc_html__( 'Save Cart', 'lean-cart-share-and-save' ),
	'default'     => $defaults['cart_save']['save_button_label'] ?? '',
] );

$sr->endSection();

// Render Save & Reset buttons
$sr->renderSubmitButtons();
