<?php

namespace Devnet\PingVid\Admin;

use Devnet\PingVid\Includes\Defaults;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
class Options {
    public static function general() {
        $options = [
            [
                'type'   => 'group',
                'name'   => 'post_types__disabled',
                'label'  => esc_html__( 'Enable For Post Types', 'pingvid' ),
                'desc'   => esc_html__( 'Choose post types where individual video overrides should be available.', 'pingvid' ),
                'fields' => self::get_post_types_as_options(),
            ],
            [
                'type'  => 'info',
                'name'  => 'info-pingvid-default-video',
                'label' => esc_html__( 'Default video', 'pingvid' ),
                'class' => 'info',
            ],
            [
                'type'    => 'checkbox',
                'name'    => 'enable_globally',
                'label'   => esc_html__( 'Enable Globally', 'pingvid' ),
                'desc'    => esc_html__( 'Automatically show the video widget on all public pages.', 'pingvid' ),
                'default' => Defaults::general( 'enable_globally' ),
            ],
            [
                'type'    => 'select',
                'name'    => 'video_platform',
                'label'   => esc_html__( 'Default Video Platform', 'pingvid' ),
                'options' => [
                    'youtube' => esc_html__( 'YouTube', 'pingvid' ),
                ],
                'default' => Defaults::general( 'video_platform' ),
            ],
            [
                'type'  => 'url',
                'name'  => 'video_url',
                'label' => esc_html__( 'Default Video URL', 'pingvid' ),
                'desc'  => esc_html__( 'Used when global video is enabled and not overridden by a post-level video.', 'pingvid' ),
            ]
        ];
        return apply_filters( 'pingvid_settings_general', $options );
    }

    public static function display() {
        $options = [
            [
                'type'    => 'select',
                'name'    => 'position',
                'label'   => esc_html__( 'Position', 'pingvid' ),
                'desc'    => '',
                'options' => [
                    'top-left'     => esc_html__( 'Top Left', 'pingvid' ),
                    'top-right'    => esc_html__( 'Top Right', 'pingvid' ),
                    'bottom-left'  => esc_html__( 'Bottom Left', 'pingvid' ),
                    'bottom-right' => esc_html__( 'Bottom Right', 'pingvid' ),
                ],
                'default' => Defaults::display( 'position' ),
            ],
            [
                'type'              => 'text',
                'name'              => 'margin_y',
                'label'             => esc_html__( 'Margin: ', 'pingvid' ),
                'placeholder'       => esc_html__( 'Vertical margin', 'pingvid' ),
                'default'           => Defaults::display( 'margin_y' ),
                'sanitize_callback' => 'sanitize_text_field',
            ],
            [
                'type'              => 'text',
                'name'              => 'margin_x',
                'label'             => esc_html__( 'Margin: ', 'pingvid' ),
                'placeholder'       => esc_html__( 'Horizontal margin', 'pingvid' ),
                'default'           => Defaults::display( 'margin_x' ),
                'sanitize_callback' => 'sanitize_text_field',
            ],
            [
                'type'              => 'number',
                'name'              => 'delay',
                'label'             => esc_html__( 'Video Popup Delay', 'pingvid' ),
                'desc'              => esc_html__( 'Enter the number of milliseconds to wait before the video popup appears after page load. Use 0 to show it immediately. 1000ms = 1s', 'pingvid' ),
                'unit'              => 'ms',
                'min'               => 0,
                'step'              => '1',
                'default'           => Defaults::display( 'delay' ),
                'sanitize_callback' => 'absint',
            ],
            [
                'type'    => 'select',
                'name'    => 'aspect_ratio',
                'label'   => esc_html__( 'Aspect Ratio', 'pingvid' ),
                'options' => [
                    '16:9' => esc_html__( '16:9 (Widescreen)', 'pingvid' ),
                    '4:3'  => esc_html__( '4:3 (Standard)', 'pingvid' ),
                    '1:1'  => esc_html__( '1:1 (Square)', 'pingvid' ),
                    '9:16' => esc_html__( '9:16 (Vertical)', 'pingvid' ),
                ],
                'default' => Defaults::general( 'aspect_ratio' ),
            ]
        ];
        return apply_filters( 'pingvid_settings_general', $options );
    }

    private static function get_post_types_as_options() {
        $post_types = get_post_types( [
            'public' => true,
        ], 'objects' );
        $options = [];
        foreach ( $post_types as $post_type ) {
            $options[] = [
                'type'  => 'checkbox',
                'name'  => $post_type->name,
                'label' => $post_type->label,
            ];
        }
        return $options;
    }

}
