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

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

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

    getDescription() 
    {
        return window.CouponsPlus.components.conditions.PaymentMethod.description;
    }
    
    getDefaultValueLabel()
    {
        return __('All')
    }

    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="M2.25 8.25h19.5M2.25 9h19.5m-16.5 5.25h6m-6 2.25h3m-3.75 3h15a2.25 2.25 0 002.25-2.25V6.75A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25v10.5A2.25 2.25 0 004.5 19.5z" />
            </svg>
        );
    }

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

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