{include file="sections/header.tpl"}
<!-- user-edit -->

<form class="form-horizontal" method="post" role="form" action="{$_url}settings/users-edit-post">
    <input type="hidden" name="csrf_token" value="{$csrf_token}">
    <div class="row">
        <div class="col-sm-6 col-md-6">
            <div class="card card-{if $d['status'] != 'Active'}danger{else}primary{/if} card-hovered card-stacked mb30">
                <div class="card-title text-center">{Lang::T('Profile')}</div>
                <div class="card-body">
                    <input type="hidden" name="id" value="{$d['id']}">
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Full Name')}</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" id="fullname" name="fullname" value="{$d['fullname']}" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Phone')}</label>
                        <div class="col-md-9">
                            <input type="tel" class="form-control" id="phone" name="phone" value="{$d['phone']}" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Email')}</label>
                        <div class="col-md-9">
                            <input type="email" class="form-control" id="email" name="email" value="{$d['email']}" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Location')}</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" id="city" name="city" placeholder="{Lang::T('City')}" value="{$d['city']}">
                        </div>
                        <div class="col-md-4">
                            <input type="text" class="form-control" id="subdistrict" name="subdistrict" placeholder="{Lang::T('Sub District')}" value="{$d['subdistrict']}">
                        </div>
                        <div class="col-md-4">
                            <input type="text" class="form-control" id="ward" name="ward" placeholder="{Lang::T('Ward')}" value="{$d['ward']}">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-sm-6 col-md-6">
            <div class="card card-{if $d['status'] != 'Active'}danger{else}primary{/if} card-hovered card-stacked mb30">
                <div class="card-title text-center">{Lang::T('Credentials')}</div>
                <div class="card-body">
                    {if ($_admin['id']) neq ($d['id'])}
                        <div class="form-group row">
                            <label class="col-md-3 control-label">{Lang::T('Status')}</label>
                            <div class="col-md-9">
                                <select name="status" id="status" class="form-control">
                                    <option value="Active" {if $d['status'] eq 'Active'}selected{/if}>{Lang::T('Active')}</option>
                                    <option value="Inactive" {if $d['status'] eq 'Inactive'}selected{/if}>{Lang::T('Inactive')}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-3 control-label">{Lang::T('User Type')}</label>
                            <div class="col-md-9">
                                <select name="user_type" id="user_type" class="form-control" onchange="checkUserType(this)">
                                    {if $_admin['user_type'] eq 'Agent'}
                                        <option value="Sales" {if $d['user_type'] eq 'Sales'}selected{/if}>{Lang::T('Sales')}</option>
                                    {/if}
                                    {if $_admin['user_type'] eq 'Admin' || $_admin['user_type'] eq 'SuperAdmin'}
                                        <option value="Report" {if $d['user_type'] eq 'Report'}selected{/if}>{Lang::T('Report Viewer')}</option>
                                        <option value="Agent" {if $d['user_type'] eq 'Agent'}selected{/if}>{Lang::T('Agent')}</option>
                                        <option value="Sales" {if $d['user_type'] eq 'Sales'}selected{/if}>{Lang::T('Sales')}</option>
                                    {/if}
                                    {if $_admin['user_type'] eq 'SuperAdmin'}
                                        <option value="Admin" {if $d['user_type'] eq 'Admin'}selected{/if}>{Lang::T('Administrator')}</option>
                                        <option value="SuperAdmin" {if $d['user_type'] eq 'SuperAdmin'}selected{/if}>{Lang::T('Super Administrator')}</option>
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="form-group row {if $d['user_type'] neq 'Sales'}hidden{/if}" id="agentChooser">
                            <label class="col-md-3 control-label">{Lang::T('Agent')}</label>
                            <div class="col-md-9">
                                <select name="root" id="root" class="form-control">
                                    {foreach $agents as $agent}
                                        <option value="{$agent['id']}" {if $d['root'] == $agent['id']}selected{/if}>{$agent['username']} | {$agent['fullname']} | {$agent['phone']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                    {/if}
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Username')}</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" id="username" name="username" value="{$d['username']}" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Password')}</label>
                        <div class="col-md-9">
                            <input type="password" class="form-control" id="password" name="password" placeholder="{Lang::T('Leave blank to keep current password')}">
                            <span class="help-block">{Lang::T('Leave Blank to do not change Password')}</span>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 control-label">{Lang::T('Confirm Password')}</label>
                        <div class="col-md-9">
                            <input type="password" class="form-control" id="cpassword" name="cpassword" placeholder="{Lang::T('Confirm Password')}">
                            <span class="help-block">{Lang::T('Leave Blank to do not change Password')}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="form-group row text-center">
        <button class="btn btn-primary" type="submit">{Lang::T('Save Changes')}</button>
        <a href="{$_url}settings/users" class="btn btn-secondary">{Lang::T('Cancel')}</a>
    </div>
</form>

{literal}
    <script>
        function checkUserType(field){
            document.getElementById('agentChooser').classList.toggle('hidden', field.value !== 'Sales');
        }
    </script>
{/literal}

{include file="sections/footer.tpl"}
