<?php

namespace CouponsPlus\App\Conditions\BuiltIn\Conditions\Time;

use Carbon\Carbon;
use CouponsPlus\App\Time\WpDateTimeZone;
use CouponsPlus\Original\Collections\Collection;

#[\AllowDynamicProperties]
Class UnitsOfTime
{
    public function getAll() : Collection
    {
        return new Collection([
            'hours' => $this->getHours(),
            'daysofweek' => $this->getDaysOfWeek(),
            'daysofmonth' => $this->getDaysOfMonth(),
            'months' => $this->getMonths(),
            'years' => $this->getYears(),
            'daysList' => [
                __('Monday', 'coupons-plus-for-woocommerce'),
                __('Tuesday', 'coupons-plus-for-woocommerce'),
                __('Wednesday', 'coupons-plus-for-woocommerce'),
                __('Thursday', 'coupons-plus-for-woocommerce'),
                __('Friday', 'coupons-plus-for-woocommerce'),
                __('Saturday', 'coupons-plus-for-woocommerce'),
                __('Sunday', 'coupons-plus-for-woocommerce')
            ],
            'daysListSundayFirst' => [
                __('Sunday', 'coupons-plus-for-woocommerce'),
                __('Monday', 'coupons-plus-for-woocommerce'),
                __('Tuesday', 'coupons-plus-for-woocommerce'),
                __('Wednesday', 'coupons-plus-for-woocommerce'),
                __('Thursday', 'coupons-plus-for-woocommerce'),
                __('Friday', 'coupons-plus-for-woocommerce'),
                __('Saturday', 'coupons-plus-for-woocommerce')
            ]
        ]);   
    }
    
    public function getHours() : Collection
    {
        return new Collection([
            __('1 A.M.', 'coupons-plus-for-woocommerce') => 1,
            __('2 A.M.', 'coupons-plus-for-woocommerce') => 2,
            __('3 A.M.', 'coupons-plus-for-woocommerce') => 3,
            __('4 A.M.', 'coupons-plus-for-woocommerce') => 4,
            __('5 A.M.', 'coupons-plus-for-woocommerce') => 5,
            __('6 A.M.', 'coupons-plus-for-woocommerce') => 6,
            __('7 A.M.', 'coupons-plus-for-woocommerce') => 7,
            __('8 A.M.', 'coupons-plus-for-woocommerce') => 8,
            __('9 A.M.', 'coupons-plus-for-woocommerce') => 9,
            __('10 A.M.', 'coupons-plus-for-woocommerce') => 10,
            __('11 A.M.', 'coupons-plus-for-woocommerce') => 11,
            __('12 P.M.', 'coupons-plus-for-woocommerce') => 12,
            __('1 P.M.', 'coupons-plus-for-woocommerce') => 13,
            __('2 P.M.', 'coupons-plus-for-woocommerce') => 14,
            __('3 P.M.', 'coupons-plus-for-woocommerce') => 15,
            __('4 P.M.', 'coupons-plus-for-woocommerce') => 16,
            __('5 P.M.', 'coupons-plus-for-woocommerce') => 17,
            __('6 P.M.', 'coupons-plus-for-woocommerce') => 18,
            __('7 P.M.', 'coupons-plus-for-woocommerce') => 19,
            __('8 P.M.', 'coupons-plus-for-woocommerce') => 20,
            __('9 P.M.', 'coupons-plus-for-woocommerce') => 21,
            __('10 P.M.', 'coupons-plus-for-woocommerce') => 22,
            __('11 P.M.', 'coupons-plus-for-woocommerce') => 23,
            __('12 A.M.', 'coupons-plus-for-woocommerce') => 0,
        ]);
    }
 
    public function getDaysOfWeek() : Collection
    {
        return new Collection([
            __('Sunday', 'coupons-plus-for-woocommerce') => Carbon::SUNDAY,
            __('Monday', 'coupons-plus-for-woocommerce') => Carbon::MONDAY,
            __('Tuesday', 'coupons-plus-for-woocommerce') => Carbon::TUESDAY,
            __('Wednesday', 'coupons-plus-for-woocommerce') => Carbon::WEDNESDAY,
            __('Thursday', 'coupons-plus-for-woocommerce') => Carbon::THURSDAY,
            __('Friday', 'coupons-plus-for-woocommerce') => Carbon::FRIDAY,
            __('Saturday', 'coupons-plus-for-woocommerce') => Carbon::SATURDAY,
        ]);
    }
          
    public function getDaysOfMonth() : Collection
    {
        return Collection::range(1, 31)->mapWithKeys(function(int $day, int $index) : array {
            return [
                'key' => $day,
                'value' => $day
            ];
        });
    }

    public function getMonths() : Collection
    {
        return new Collection([
            __('January', 'coupons-plus-for-woocommerce') => 1,
            __('February', 'coupons-plus-for-woocommerce') => 2,
            __('March', 'coupons-plus-for-woocommerce') => 3,
            __('April', 'coupons-plus-for-woocommerce') => 4,
            __('May', 'coupons-plus-for-woocommerce') => 5,
            __('June', 'coupons-plus-for-woocommerce') => 6,
            __('July', 'coupons-plus-for-woocommerce') => 7,
            __('August', 'coupons-plus-for-woocommerce') => 8,
            __('September', 'coupons-plus-for-woocommerce') => 9,
            __('October', 'coupons-plus-for-woocommerce') => 10,
            __('November', 'coupons-plus-for-woocommerce') => 11,
            __('December', 'coupons-plus-for-woocommerce') => 12,
        ]);
    }

    public function getYears() : Collection
    {
        (integer) $currentYear = Carbon::now(WpDateTimeZone::getWpTimezone())->year;

        return Collection::range(
            $start = $currentYear,
            $end = $currentYear + 20
        )->mapWithKeys(function(int $day, int $index) : array {
            return [
                'key' => $day,
                'value' => $day
            ];
        });
    }
}
