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

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

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

    getDescription() 
    {
        return window.CouponsPlus.components.conditions.ShippingMethod.description;
    }
    
    c

    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="M21.75 9v.906a2.25 2.25 0 01-1.183 1.981l-6.478 3.488M2.25 9v.906a2.25 2.25 0 001.183 1.981l6.478 3.488m8.839 2.51l-4.66-2.51m0 0l-1.023-.55a2.25 2.25 0 00-2.134 0l-1.022.55m0 0l-4.661 2.51m16.5 1.615a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V8.844a2.25 2.25 0 011.183-1.98l7.5-4.04a2.25 2.25 0 012.134 0l7.5 4.04a2.25 2.25 0 011.183 1.98V19.5z" />
                </svg>
        )
    }

    getFields() 
    {
        return [
            new FieldsGroup([
                {
                    type: 'select',
                    width: 'auto',
                    options:window.CouponsPlus.components.conditions.ShippingMethod.fields.inclusionType.meta['_allowed'],
                    labels: {
                    },
                    temporaryID: this.data.temporaryID,
                    propertyName: 'options.inclusionType',
                    getValue: () => {
                        return invert(CouponsPlus.components.conditions.ShippingMethod.fields.inclusionType.meta['_allowed'])[this.data.options.inclusionType]
                    },
                },
                {
                    type: 'multiple',
                    subtype: 'multiple',
                    width: '',
                    options: Object.keys(CouponsPlus.shippingMethods).map(role => ({value: role, label:window.CouponsPlus.shippingMethods[role]})),
                    labels: {
                    },
                    temporaryID: this.data.temporaryID,
                    propertyName: 'options.ids',
                    getValue: () => {
                        return this.data.options.ids.map(role => ({value: role, label:window.CouponsPlus.shippingMethods[role]}))
                    },
                    show: () => true
                },/**/
            ], {
                customAlignmentClass: this.data.options.inclusionType === 'forbidden'? 'items-start' : 'items-end'
            }),
        ]
    }

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