<commit_before>import m from 'mithril';
import _ from 'underscore';
import h from '../h';
import inlineError from '../c/inline-error';

const shippingFeeInput = {
    oninit: function(vnode) {
        const states = vnode.attrs.states;
        const fee = vnode.attrs.fee,
            fees = vnode.attrs.fees,
            deleted = h.toggleProp(false, true),
            stateInUse = (state) => {
                const destinations = _.map(fees(), fee => fee.destination());
                return state.acronym !== fee.destination() && _.contains(destinations, state.acronym);
            },
            applyMask = _.compose(fee.value, h.applyMonetaryMask);

        _.extend(fee, { deleted });
        fee.value(fee.value() ? `${h.formatNumber(fee.value(), 2, 3)}` : '0,00');
        vnode.state = {
            fee,
            applyMask,
            fees,
            deleted,
            feeValue: fee.value,
            stateInUse,
            states
        };
    },
    view: function({state}) {
        const deleted = state.deleted,
            othersCount = _.filter(state.fees(), fee => fee.destination !== 'others' && fee.destination !== 'international').length,
            states = state.states;

        return m(`div${deleted() ? '.w-hidden' : ''}`, [
            m('.u-marginbottom-10.w-row', [
                m('.w-col.w-col-6',

                    (
                        state.fee.destination() === 'others' ? [

                            m('input[type=\'hidden\']', {
                                value: 'others'
                            }),
                            m('label.field-label.fontsize-smallest',
                                (othersCount > 0 ? 'Resto do Brasil' : 'Todos os estados do Brasil')
                            )
                        ] :

                        state.fee.destination() === 'international' ?

                        [
                            m('input[type=\'hidden\']', {
                                value: 'international'
                            }),
                            m('label.field-label.fontsize-smallest',
                                'Internacional'
                            )
                        ] :

                        m('select.fontsize-smallest.text-field.text-field-light.w-select', {
                            class: state.fee.error ? 'error' : false,
                            value: state.fee.destination(),
                            onchange: m.withAttr('value', state.fee.destination)
                        }, [
                            (_.map(states(), state =>
                                m('option', {
                                    value: state.acronym,
                                    disabled: state.stateInUse(state)
                                },
                                    state.name
                                )))
                        ]))
                ),
                m('.w-col.w-col-1'),
                m('.w-col.w-col-4',
                    m('.w-row', [
                        m('.no-hover.positive.prefix.text-field.w-col.w-col-3',
                            m('.fontcolor-secondary.fontsize-mini.u-text-center',
                                'R$'
                            )
                        ),
                        m('.w-col.w-col-9',
                            m('input.positive.postfix.text-field.w-input', {
                                value: state.feeValue(),
                                autocomplete: 'off',
                                type: 'text',
                                onkeyup: m.withAttr('value', state.applyMask),
                                oninput: m.withAttr('value', state.feeValue)
                            })
                        )
                    ])
                ),
                m('.w-col.w-col-1', [
                    m('input[type=\'hidden\']', {<commit_msg>fixing state add to reward shipping fee<commit_after>import m from 'mithril';
import _ from 'underscore';
import h from '../h';
import inlineError from '../c/inline-error';

const shippingFeeInput = {
    oninit: function(vnode) {
        const states = vnode.attrs.states;
        const fee = vnode.attrs.fee,
            fees = vnode.attrs.fees,
            deleted = h.toggleProp(false, true),
            stateInUse = stateData => {
                const destinations = _.map(fees(), fee => fee.destination());
                return stateData.acronym !== fee.destination() && _.contains(destinations, stateData.acronym);
            },
            applyMask = _.compose(fee.value, h.applyMonetaryMask);

        _.extend(fee, { deleted });
        fee.value(fee.value() ? `${h.formatNumber(fee.value(), 2, 3)}` : '0,00');
        vnode.state = {
            fee,
            applyMask,
            fees,
            deleted,
            feeValue: fee.value,
            stateInUse,
            states
        };
    },
    view: function({state}) {
        const deleted = state.deleted,
            othersCount = _.filter(state.fees(), fee => fee.destination !== 'others' && fee.destination !== 'international').length,
            states = state.states;

        return m(`div${deleted() ? '.w-hidden' : ''}`, [
            m('.u-marginbottom-10.w-row', [
                m('.w-col.w-col-6',

                    (
                        state.fee.destination() === 'others' ? [

                            m('input[type=\'hidden\']', {
                                value: 'others'
                            }),
                            m('label.field-label.fontsize-smallest',
                                (othersCount > 0 ? 'Resto do Brasil' : 'Todos os estados do Brasil')
                            )
                        ] :

                        state.fee.destination() === 'international' ?

                        [
                            m('input[type=\'hidden\']', {
                                value: 'international'
                            }),
                            m('label.field-label.fontsize-smallest',
                                'Internacional'
                            )
                        ] :

                        m('select.fontsize-smallest.text-field.text-field-light.w-select', {
                            class: state.fee.error ? 'error' : false,
                            value: state.fee.destination(),
                            onchange: m.withAttr('value', state.fee.destination)
                        }, [
                            (_.map(states(), stateData =>
                                m('option', {
                                    value: stateData.acronym,
                                    disabled: state.stateInUse(stateData)
                                },
                                    stateData.name
                                )))
                        ]))
                ),
                m('.w-col.w-col-1'),
                m('.w-col.w-col-4',
                    m('.w-row', [
                        m('.no-hover.positive.prefix.text-field.w-col.w-col-3',
                            m('.fontcolor-secondary.fontsize-mini.u-text-center',
                                'R$'
                            )
                        ),
                        m('.w-col.w-col-9',
                            m('input.positive.postfix.text-field.w-input', {
                                value: state.feeValue(),
                                autocomplete: 'off',
                                type: 'text',
                                onkeyup: m.withAttr('value', state.applyMask),
                                oninput: m.withAttr('value', state.feeValue)
                            })
                        )
                    ])
                ),
                m('.w-col.w-col-1', [
                    m('input[type=\'hidden\']', {
{'fraction_non_alphanumeric': 0.1289347771342231, 'fraction_numerical': 0.0035255603122639136, 'mean_word_length': 0.8952517298973992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3084791', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1900, 'n_words': 292}