$(document).ready(function () {
    $('.stamp-picture-input').change(function (event) {
        if (this.files.length > 0) {
            var file = event.target.files[0];
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function () {
                $("#imgStamp").attr('src', reader.result);
            };
        }
    });
    initial()
})
async function initial() {
    await getCompanyInfo();
    closeLoading();
    $("#divMain").show();
}
$('#btnHoghoghi1').click(function () {
    inactiveIsReal();
});
$('#btnHaghighi1').click(function () {
    activeIsReal();
});
function activeIsReal() {
    $('#btnHaghighi1').removeClass('inactive-btn').addClass('active-btn')
    $('#btnHoghoghi1').removeClass('active-btn').addClass('inactive-btn');
    $("#txtMelliCode").inputmask("9999999999");
}
function inactiveIsReal() {
    $('#btnHoghoghi1').removeClass('inactive-btn').addClass('active-btn');
    $('#btnHaghighi1').removeClass('active-btn').addClass('inactive-btn');
    $("#txtMelliCode").inputmask("99999999999");
}
function saveCompanyInfo() {
    var data = getJsonValue();
    if ($('#btnHaghighi').hasClass('active-btn') == "true")
        data['IsReal'] = true;
    else
        data['IsReal'] = false;
    var companyImg = $('.picture-img > img').attr('src');
    data["FileImage"] = companyImg ? companyImg : "../img/pages/menu/411.svg";
    data["Stamp64"] = $('#imgStamp').attr('src');
    ajax({
        loading: true,
        url: "GeneralApi/UpdateCompanyInfo",
        data: data,
        success: function (result) {
            refreshParent('refreshCompanyInfo(\'' + data["FileImage"] + '\')');
            closeTopModal();
        }
    });
}
async function getCompanyInfo() {
    await ajax({
        url: "GeneralApi/GetCompanyInfo",
        success: function (result) {
            if (result != null) {
                if (result.IsReal) {
                    activeIsReal();
                    $("#txtMelliCode").attr("data-mask", "codeHaghighi");
                }
                else {
                    inactiveIsReal();
                    $("#txtMelliCode").attr("data-mask", "codeHoghoghi");
                }
                setJsonValue(result);
                var companyImg = result.FileImage != null ? "data:image/jpg;base64," + result.FileImage : "../img/pages/menu/411.svg";
                $(".picture-img").html("<img src='" + companyImg + "' />");
                $("#imgStamp").attr("src", result.Stamp64 ? "data:image/jpg;base64," + result.Stamp64 : "../img/stamp.svg");
            }
        }
    });
}
function deleteStamp() {
    $("#imgStamp").attr('src', "../img/stamp.svg");
}
