import FieldsGroup from '../../FieldsGroup';
import { CouponsPlus, __ } from '../../globals';
import Condition from '../Condition';
import { invert } from 'lodash';

export default class Date extends Condition
{
    static TYPE =window.CouponsPlus.components.conditions.Date.type;
    
    getComponent() 
    {
        return window.CouponsPlus.components.conditions.Date;       
    }

    getTitle() 
    {
        return window.CouponsPlus.components.conditions.Date.name;
    }

    getDescription() 
    {
        return window.CouponsPlus.components.conditions.Date.description;
    }
    
    getIcon()
{
        return (<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
  <path stroke-linecap="round" stroke-linejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5" />
</svg>
);
    }

    getFields() 
    {
        return [
            new FieldsGroup([
                {
                    type: 'select',
                    width: 'auto',
                    options:window.CouponsPlus.components.conditions.Date.fields.type.meta['_allowed'],
                    labels: {
                    },
                    temporaryID: this.data.temporaryID,
                    propertyName: 'options.type',
                    getValue: () => {
                        return invert(CouponsPlus.components.conditions.Date.fields.type.meta['_allowed'])[this.data.options.type]
                    },
                },
                {
                    type: 'date',
                    width: 'auto',
                    labels: {
                    },
                    temporaryID: this.data.temporaryID,
                    propertyName: 'options.date.exact',
                    getValue: () => {
                        return this.data.options.date.exact
                    },
                    show: () => this.data.options.type !== 'range'
                },
                {
                    type: 'date',
                    width: 'auto',
                    labels: {
                        left: __('From',window.CouponsPlus.textDomain)
                    },
                    temporaryID: this.data.temporaryID,
                    propertyName: 'options.date.from',
                    getValue: () => {
                        return this.data.options.date.from
                    },
                    show: () => this.data.options.type === 'range'
                },
                {
                    type: 'date',
                    width: 'auto',
                    labels: {
                        left: __('To',window.CouponsPlus.textDomain)
                    },
                    temporaryID: this.data.temporaryID,
                    propertyName: 'options.date.to',
                    getValue: () => {
                        return this.data.options.date.to
                    },
                    show: () => this.data.options.type === 'range'
                },
            ])
        ]
    }

    getDefaultOptions()
{
        return window.CouponsPlus.components.conditions.Date.defaultOptions;
    }
}