<?php
if ( ! class_exists( 'Draly_Dropshipping_Starter_Elementor' ) ) {
	class Draly_Dropshipping_Starter_Elementor extends \Elementor\Widget_Base {

		public $name = '';
		public $title = '';
		public $icon = '';
		public $categories = [ 'draly-dropshipping-starter' ];

		public function get_name() {
			return $this->name;
		}

		public function get_title() {
			return 'Draly: ' . $this->title;
		}

		public function get_icon() {
			return $this->icon;
		}

		public function get_categories() {
			return $this->categories;
		}

		public static function draly_dropshipping_starter_elementor_taxonomy() {
			$taxonomy_options   = array(
				'' => esc_html__( 'All', 'draly-dropshipping-starter' )
			);
			$args               = array();
			$product_categories = get_terms( 'product_cat', $args );
			if ( ! empty( $product_categories ) ) {
				foreach ( $product_categories as $key => $value ) {
					$taxonomy_options[ $value->slug ] = $value->name;
				}
			}

			return $taxonomy_options;
		}

		public static function draly_dropshipping_starter_elementor_product_category() {
			$product_category_options = array();
			$args                     = array();
			$product_categories       = get_terms( 'product_cat', $args );
			if ( ! empty( $product_categories ) ) {
				foreach ( $product_categories as $key => $value ) {
					$product_category_options[ $value->slug ] = $value->name;
				}
			}

			return $product_category_options;
		}

		public static function draly_dropshipping_starter_elementor_category() {
			$category_options = array(
				'' => esc_html__( 'All', 'draly-dropshipping-starter' )
			);
			$args             = array();
			$categories       = get_categories( $args );
			if ( ! empty( $categories ) ) {
				foreach ( $categories as $category ) {
					$category_options[ $category->slug ] = $category->name;
				}
			}

			return $category_options;
		}

		public static function draly_dropshipping_starter_elementor_size() {
			$size_width_options = array();
			$width              = 300;
			$height             = 300;
			if ( function_exists( 'wc_get_image_size' ) ) {
				$size   = wc_get_image_size( 'shop_catalog' );
				$width  = isset( $size['width'] ) ? $size['width'] : $width;
				$height = isset( $size['height'] ) ? $size['height'] : $height;
			}
			for ( $i = 100; $i < $width; $i = $i + 10 ) {
				array_push( $size_width_options, $i );
			}
			$size_options                           = array();
			$size_options[ $width . 'x' . $height ] = $width . 'x' . $height;
			foreach ( $size_width_options as $k => $w ) {
				$w = intval( $w );
				if ( isset( $width ) && $width > 0 ) {
					$h = round( $height * $w / $width );
				} else {
					$h = $w;
				}
				$size_options[ $w . 'x' . $h ] = $w . 'x' . $h;
			}
			$size_options['custom'] = esc_html__( 'Custom', 'draly-dropshipping-starter' );

			return $size_options;
		}
	}
}