{if $successful}
    {include file="$template/includes/alert.tpl" type="success" msg="{lang key='changessavedsuccessfully'}" textcenter=true}
{/if}

{if $errormessage}
    {include file="$template/includes/alert.tpl" type="error" errorshtml=$errormessage}
{/if}

{if in_array('state', $optionalFields)}
    <script>
        var stateNotRequired = true;
    </script>
{/if}

<script type="text/javascript" src="{$BASE_PATH_JS}/StatesDropdown.js"></script>

<form method="post" action="?action=details" role="form" class="dashboard-account-settings">

    <section class="dashboard-page-header">
        <div>
            <h1 class="dashboard-page-title">{lang key='accountinfo'}</h1>
            <p class="dashboard-page-subtitle">Cloud Hosting Platform</p>
        </div>
        <div class="dashboard-page-breadcrumb">
            {include file="$template/includes/breadcrumb.tpl"}
        </div>
    </section>

    <section class="dashboard-account-settings__layout dashboard-panel">
        <div class="dashboard-account-settings__content">
            <div class="card dashboard-settings-card dashboard-settings-card--primary">
                <div class="card-body">
                        <div class="dashboard-settings-card__heading">
                            <span class="dashboard-page-heading__icon dashboard-page-heading__icon--mint">
                                <i class="far fa-user"></i>
                            </span>
                            <div>
                            <h3 class="card-title">Contact Details</h3>
                            <p class="dashboard-panel__copy">{lang key='clientareaupdateyourdetails'}</p>
                        </div>
                    </div>

                    <div class="row d-md-block">
                        <div class="col-md-6 float-md-left">

                            <div class="form-group">
                                <label for="inputFirstName" class="col-form-label">{lang key='clientareafirstname'}</label>
                                <input type="text" name="firstname" id="inputFirstName" value="{$clientfirstname}" placeholder="{lang key='clientareafirstname'}"{if in_array('firstname', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputLastName" class="col-form-label">{lang key='clientarealastname'}</label>
                                <input type="text" name="lastname" id="inputLastName" value="{$clientlastname}" placeholder="{lang key='clientarealastname'}"{if in_array('lastname', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputCompanyName" class="col-form-label">{lang key='clientareacompanyname'}</label>
                                <input type="text" name="companyname" id="inputCompanyName" value="{$clientcompanyname}" placeholder="{lang key='clientareacompanyname'}"{if in_array('companyname', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputEmail" class="col-form-label">{lang key='clientareaemail'}</label>
                                <input type="email" name="email" id="inputEmail" value="{$clientemail}" placeholder="{lang key='clientareaemail'}"{if in_array('email', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                        </div>
                        <div class="col-md-6 col-12 float-md-right">

                            <div class="form-group">
                                <label for="inputAddress1" class="col-form-label">{lang key='clientareaaddress1'}</label>
                                <input type="text" name="address1" id="inputAddress1" value="{$clientaddress1}" placeholder="{lang key='clientareaaddress1'}"{if in_array('address1', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputAddress2" class="col-form-label">{lang key='clientareaaddress2'}</label>
                                <input type="text" name="address2" id="inputAddress2" value="{$clientaddress2}" placeholder="{lang key='clientareaaddress2'}"{if in_array('address2', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputCity" class="col-form-label">{lang key='clientareacity'}</label>
                                <input type="text" name="city" id="inputCity" value="{$clientcity}" placeholder="{lang key='clientareacity'}"{if in_array('city', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputState" class="col-form-label">{lang key='clientareastate'}</label>
                                <input type="text" name="state" id="inputState" value="{$clientstate}" placeholder="{lang key='clientareastate'}"{if in_array('state', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label for="inputPostcode" class="col-form-label">{lang key='clientareapostcode'}</label>
                                <input type="text" name="postcode" id="inputPostcode" value="{$clientpostcode}" placeholder="{lang key='clientareapostcode'}"{if in_array('postcode', $uneditablefields)} disabled="disabled"{/if} class="form-control" />
                            </div>

                            <div class="form-group">
                                <label class="col-form-label" for="country">{lang key='clientareacountry'}</label>
                                {$clientcountriesdropdown}
                            </div>

                            <div class="form-group">
                                <label for="inputPhone" class="col-form-label">{lang key='clientareaphonenumber'}</label>
                                <input type="tel" name="phonenumber" id="inputPhone" value="{$clientphonenumber}" placeholder="{lang key='clientareaphonenumber'}"{if in_array('phonenumber',$uneditablefields)} disabled=""{/if} class="form-control" />
                            </div>

                        </div>
                        <div class="col-md-6 col-12 float-md-left">

                            <div class="form-group">
                                <label for="inputPaymentMethod" class="col-form-label">{lang key='paymentmethod'}</label>
                                <select name="paymentmethod" id="inputPaymentMethod" class="form-control custom-select">
                                    <option value="none">{lang key='paymentmethoddefault'}</option>
                                    {foreach $paymentmethods as $method}
                                    <option value="{$method.sysname}"{if $method.sysname eq $defaultpaymentmethod} selected="selected"{/if}>{$method.name}</option>
                                    {/foreach}
                                </select>
                            </div>

                            <div class="form-group">
                                <label for="inputBillingContact" class="col-form-label">{lang key='defaultbillingcontact'}</label>
                                <select name="billingcid" id="inputBillingContact" class="form-control custom-select">
                                    <option value="0">{lang key='usedefaultcontact'}</option>
                                    {foreach $contacts as $contact}
                                    <option value="{$contact.id}"{if $contact.id eq $billingcid} selected="selected"{/if}>{$contact.name}</option>
                                    {/foreach}
                                </select>
                            </div>

                            <div class="form-group">
                                <label for="inputLanguage" class="col-form-label">{lang key='clientarealanguage'}</label>
                                <select name="accountLanguage" id="inputAccountLanguage" class="form-control custom-select"
                                    {if in_array('language', $uneditablefields)} disabled="disabled"{/if}>
                                    <option value="">{lang key='default'}</option>
                                    {foreach $languages as $language}
                                        <option value="{$language}"{if $language eq $clientLanguage} selected="selected"{/if}
                                            >{$language|ucfirst}</option>
                                    {/foreach}
                                </select>
                            </div>

                            {if $showTaxIdField}
                                <div class="form-group">
                                    <label for="inputTaxId" class="col-form-label">{lang key=$taxIdLabel}</label>
                                    <input type="text" name="tax_id" id="inputTaxId" class="form-control" value="{$clientTaxId}"{if in_array('tax_id', $uneditablefields)} disabled="disabled"{/if} />
                                </div>
                            {/if}

                            {if $customfields}
                                {foreach $customfields as $customfield}
                                    <div class="form-group">
                                        <label class="col-form-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                                        <div class="control">
                                            {$customfield.input} {$customfield.description}
                                        </div>
                                    </div>
                                {/foreach}
                            {/if}

                        </div>

                    </div>
                </div>
            </div>

            {if $emailPreferencesEnabled}
                <div class="card dashboard-settings-card dashboard-settings-card--preferences">
                    <div class="card-body">
                        <div class="dashboard-settings-card__heading">
                            <span class="dashboard-page-heading__icon dashboard-page-heading__icon--violet">
                                <i class="far fa-envelope"></i>
                            </span>
                            <div>
                                <h3 class="card-title">Email Preferences</h3>
                                <p class="dashboard-panel__copy">Choose which account, billing, and service notifications you would like to receive.</p>
                            </div>
                        </div>

                        <div class="controls form-check dashboard-email-preferences dashboard-email-preferences--grid">
                            {foreach $emailPreferences as $emailType => $value}
                                <label class="dashboard-email-preference dashboard-email-preference--card">
                                    <input type="hidden" name="email_preferences[{$emailType}]" value="0">
                                    <input type="checkbox" class="form-check-input" name="email_preferences[{$emailType}]" id="{$emailType}Emails" value="1"{if $value} checked="checked"{/if} />
                                    <span class="dashboard-email-preference__label">{lang key="emailPreferences."|cat:$emailType}</span>
                                </label>
                            {/foreach}
                        </div>
                    </div>
                </div>
            {/if}

            {if $showMarketingEmailOptIn}
                <div class="card dashboard-settings-card dashboard-settings-card--marketing">
                    <div class="card-body">
                        <div class="dashboard-settings-card__heading">
                            <span class="dashboard-page-heading__icon dashboard-page-heading__icon--mint">
                                <i class="far fa-paper-plane"></i>
                            </span>
                            <div>
                                <h3 class="card-title">{lang key='emailMarketing.joinOurMailingList'}</h3>
                                <p>{$marketingEmailOptInMessage}</p>
                            </div>
                        </div>
                        <div class="dashboard-marketing-choice">
                            <label class="dashboard-marketing-choice__item{if $marketingEmailOptIn} is-active{/if}">
                                <input type="radio" name="marketingoptin" value="1"{if $marketingEmailOptIn} checked{/if}>
                                <span>{lang key='yes'}</span>
                            </label>
                            <label class="dashboard-marketing-choice__item{if !$marketingEmailOptIn} is-active{/if}">
                                <input type="radio" name="marketingoptin" value="0"{if !$marketingEmailOptIn} checked{/if}>
                                <span>{lang key='no'}</span>
                            </label>
                        </div>
                    </div>
                </div>
            {/if}

            <div class="form-group text-center dashboard-settings-actions">
                <input class="btn btn-primary" type="submit" name="save" value="{lang key='clientareasavechanges'}" />
                <input class="btn btn-default" type="reset" value="{lang key='cancel'}" />
            </div>
        </div>

        <aside class="dashboard-account-settings__aside">
            <div class="dashboard-settings-aside-card dashboard-settings-aside-card--violet">
                <span class="dashboard-settings-aside-card__icon"><i class="far fa-user-circle"></i></span>
                <h4>Default Contact</h4>
                <p>Use the default contact on your account for billing and account communication.</p>
                <div class="dashboard-settings-aside-card__chip">
                    <i class="far fa-user"></i>
                    <span>Use Default Contact</span>
                    <i class="far fa-check-circle"></i>
                </div>
            </div>
            <div class="dashboard-settings-aside-card dashboard-settings-aside-card--mint">
                <span class="dashboard-settings-aside-card__icon"><i class="far fa-shield-check"></i></span>
                <h4>{lang key='supportticketsstaff'|default:$LANG.clientareanavsupporttickets|default:$LANG.navsupport}</h4>
                <p>{lang key='clientareaupdateyourdetails'}</p>
            </div>
        </aside>
    </section>

</form>
