<?php
/**
 * Base class for MuchWOW Elementor widgets.
 *
 * @package Shabnam_MuchWOW
 */

defined( 'ABSPATH' ) || exit;

abstract class Shabnam_Elementor_Widget_Base extends \Elementor\Widget_Base {
	public function get_categories() {
		return array( 'shabnam-muchwow' );
	}

	public function get_style_depends() {
		return array( 'shabnam-muchwow-core', 'shabnam-muchwow-rtl', 'shabnam-wordpress', 'shabnam-elementor' );
	}

	public function get_script_depends() {
		return array( 'shabnam-app' );
	}

	public function get_keywords() {
		return array( 'muchwow', 'shabnam', 'rtl', 'فارسی' );
	}


	/**
	 * Register shared appearance controls used by MuchWOW widgets.
	 * These controls intentionally target only the current Elementor wrapper so
	 * each widget can be styled independently without changing global theme data.
	 */
	protected function shabnam_register_common_style_controls() {
		$this->start_controls_section(
			'shabnam_style_section',
			array(
				'label' => __( 'استایل بخش', 'shabnam-muchwow' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_control(
			'shabnam_section_background',
			array(
				'label'     => __( 'رنگ پس‌زمینه', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .shabnam-elementor-section'                => 'background-color: {{VALUE}} !important;',
					'{{WRAPPER}} .shabnam-elementor-section .section-outer' => 'background-color: {{VALUE}} !important;',
				),
			)
		);
		$this->add_control(
			'shabnam_text_color',
			array(
				'label'     => __( 'رنگ متن', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .shabnam-elementor-section'   => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .shabnam-elementor-section p' => 'color: {{VALUE}} !important;',
				),
			)
		);
		$this->add_control(
			'shabnam_heading_color',
			array(
				'label'     => __( 'رنگ عنوان‌ها', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .shabnam-elementor-section h1, {{WRAPPER}} .shabnam-elementor-section h2, {{WRAPPER}} .shabnam-elementor-section h3, {{WRAPPER}} .shabnam-elementor-section h4, {{WRAPPER}} .shabnam-elementor-section h5, {{WRAPPER}} .shabnam-elementor-section h6' => 'color: {{VALUE}} !important;',
				),
			)
		);
		$this->add_control(
			'shabnam_accent_color',
			array(
				'label'     => __( 'رنگ تأکیدی', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .shabnam-elementor-section .text-secondary, {{WRAPPER}} .shabnam-elementor-section .text-primary, {{WRAPPER}} .shabnam-elementor-section .text-tertiary, {{WRAPPER}} .shabnam-elementor-section .stroke-text' => 'color: {{VALUE}} !important; -webkit-text-stroke-color: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'shabnam_card_background',
			array(
				'label'     => __( 'پس‌زمینه کارت‌ها', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .shabnam-elementor-section .features-item, {{WRAPPER}} .shabnam-elementor-section .roadmap-item, {{WRAPPER}} .shabnam-elementor-section .tokenomics-item, {{WRAPPER}} .shabnam-elementor-section .faq-item, {{WRAPPER}} .shabnam-elementor-section .shabnam-post-card' => 'background-color: {{VALUE}} !important;',
				),
			)
		);
		$this->add_control(
			'shabnam_border_color',
			array(
				'label'     => __( 'رنگ حاشیه‌ها', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .shabnam-elementor-section .border, {{WRAPPER}} .shabnam-elementor-section .features-item, {{WRAPPER}} .shabnam-elementor-section .shabnam-post-card' => 'border-color: {{VALUE}} !important;',
				),
			)
		);
		$this->add_control(
			'shabnam_button_background',
			array(
				'label'     => __( 'رنگ دکمه‌ها', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .shabnam-elementor-section .btn' => 'background: {{VALUE}} !important; background-image: none !important;' ),
			)
		);
		$this->add_control(
			'shabnam_button_text_color',
			array(
				'label'     => __( 'رنگ متن دکمه‌ها', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .shabnam-elementor-section .btn, {{WRAPPER}} .shabnam-elementor-section .btn span' => 'color: {{VALUE}} !important;' ),
			)
		);
		$this->add_control(
			'shabnam_button_hover_background',
			array(
				'label'     => __( 'رنگ دکمه در حالت هاور', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .shabnam-elementor-section .btn:hover' => 'background: {{VALUE}} !important; background-image: none !important;' ),
			)
		);
		$this->add_responsive_control(
			'shabnam_image_radius',
			array(
				'label'      => __( 'گردی گوشه تصاویر', 'shabnam-muchwow' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 80 ) ),
				'selectors'  => array( '{{WRAPPER}} .shabnam-elementor-section img' => 'border-radius: {{SIZE}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'shabnam_section_padding',
			array(
				'label'      => __( 'فاصله داخلی بخش', 'shabnam-muchwow' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', 'rem', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .shabnam-elementor-section .section-outer' => 'padding-top: {{TOP}}{{UNIT}} !important; padding-right: {{RIGHT}}{{UNIT}} !important; padding-bottom: {{BOTTOM}}{{UNIT}} !important; padding-left: {{LEFT}}{{UNIT}} !important;',
				),
			)
		);
		$this->add_responsive_control(
			'shabnam_section_radius',
			array(
				'label'      => __( 'گردی گوشه‌ها', 'shabnam-muchwow' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 80 ) ),
				'selectors'  => array(
					'{{WRAPPER}} .shabnam-elementor-section, {{WRAPPER}} .shabnam-elementor-section .features-item, {{WRAPPER}} .shabnam-elementor-section .roadmap-item, {{WRAPPER}} .shabnam-elementor-section .shabnam-post-card' => 'border-radius: {{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'shabnam_text_align',
			array(
				'label'     => __( 'تراز محتوا', 'shabnam-muchwow' ),
				'type'      => \Elementor\Controls_Manager::CHOOSE,
				'options'   => array(
					'right'  => array( 'title' => __( 'راست', 'shabnam-muchwow' ), 'icon' => 'eicon-text-align-right' ),
					'center' => array( 'title' => __( 'وسط', 'shabnam-muchwow' ), 'icon' => 'eicon-text-align-center' ),
					'left'   => array( 'title' => __( 'چپ', 'shabnam-muchwow' ), 'icon' => 'eicon-text-align-left' ),
				),
				'selectors' => array( '{{WRAPPER}} .shabnam-elementor-section' => 'text-align: {{VALUE}};' ),
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'shabnam_typography_section',
			array(
				'label' => __( 'تایپوگرافی', 'shabnam-muchwow' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			array(
				'name'     => 'shabnam_heading_typography',
				'label'    => __( 'عنوان‌ها', 'shabnam-muchwow' ),
				'selector' => '{{WRAPPER}} .shabnam-elementor-section h1, {{WRAPPER}} .shabnam-elementor-section h2, {{WRAPPER}} .shabnam-elementor-section h3, {{WRAPPER}} .shabnam-elementor-section h4, {{WRAPPER}} .shabnam-elementor-section h5, {{WRAPPER}} .shabnam-elementor-section h6',
			)
		);
		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			array(
				'name'     => 'shabnam_body_typography',
				'label'    => __( 'متن‌ها', 'shabnam-muchwow' ),
				'selector' => '{{WRAPPER}} .shabnam-elementor-section p, {{WRAPPER}} .shabnam-elementor-section li, {{WRAPPER}} .shabnam-elementor-section span',
			)
		);
		$this->end_controls_section();
	}

	/**
	 * Add a normal Elementor URL control.
	 *
	 * @param string $id      Control ID.
	 * @param string $label   Label.
	 * @param string $default Default URL.
	 */
	protected function shabnam_add_url_control( $id, $label, $default = '' ) {
		$this->add_control(
			$id,
			array(
				'label'       => $label,
				'type'        => \Elementor\Controls_Manager::URL,
				'placeholder' => 'https://',
				'default'     => array( 'url' => $default ),
			)
		);
	}

	/**
	 * Get an Elementor media URL with a safe fallback.
	 *
	 * @param array  $media    Media control value.
	 * @param string $fallback Fallback URL.
	 * @return string
	 */
	protected function shabnam_media_url( $media, $fallback = '' ) {
		return ! empty( $media['url'] ) ? $media['url'] : $fallback;
	}
}
