import {CalendarDate as $9a4e222e1bd2b190$export$99faa760c7908e4f} from "../CalendarDate.js";

/*
 * Copyright 2020 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ // Portions of the code in this file are based on code from ICU.
// Original licensing can be found in the NOTICE file in the root directory of this source tree.

const $a938ddf4fc940323$var$CIVIL_EPOC = 1948440; // CE 622 July 16 Friday (Julian calendar) / CE 622 July 19 (Gregorian calendar)
const $a938ddf4fc940323$var$ASTRONOMICAL_EPOC = 1948439; // CE 622 July 15 Thursday (Julian calendar)
const $a938ddf4fc940323$var$UMALQURA_YEAR_START = 1300;
const $a938ddf4fc940323$var$UMALQURA_YEAR_END = 1600;
const $a938ddf4fc940323$var$UMALQURA_START_DAYS = 460322;
function $a938ddf4fc940323$var$islamicToJulianDay(epoch, year, month, day) {
    return day + Math.ceil(29.5 * (month - 1)) + (year - 1) * 354 + Math.floor((3 + 11 * year) / 30) + epoch - 1;
}
function $a938ddf4fc940323$var$julianDayToIslamic(calendar, epoch, jd) {
    let year = Math.floor((30 * (jd - epoch) + 10646) / 10631);
    let month = Math.min(12, Math.ceil((jd - (29 + $a938ddf4fc940323$var$islamicToJulianDay(epoch, year, 1, 1))) / 29.5) + 1);
    let day = jd - $a938ddf4fc940323$var$islamicToJulianDay(epoch, year, month, 1) + 1;
    return new (0, $9a4e222e1bd2b190$export$99faa760c7908e4f)(calendar, year, month, day);
}
function $a938ddf4fc940323$var$isLeapYear(year) {
    return (14 + 11 * year) % 30 < 11;
}
class $a938ddf4fc940323$export$2066795aadd37bfc {
    fromJulianDay(jd) {
        return $a938ddf4fc940323$var$julianDayToIslamic(this, $a938ddf4fc940323$var$CIVIL_EPOC, jd);
    }
    toJulianDay(date) {
        return $a938ddf4fc940323$var$islamicToJulianDay($a938ddf4fc940323$var$CIVIL_EPOC, date.year, date.month, date.day);
    }
    getDaysInMonth(date) {
        let length = 29 + date.month % 2;
        if (date.month === 12 && $a938ddf4fc940323$var$isLeapYear(date.year)) length++;
        return length;
    }
    getMonthsInYear() {
        return 12;
    }
    getDaysInYear(date) {
        return $a938ddf4fc940323$var$isLeapYear(date.year) ? 355 : 354;
    }
    getMaximumMonthsInYear() {
        return 12;
    }
    getMaximumDaysInMonth() {
        return 30;
    }
    getYearsInEra() {
        // 9999 gregorian
        return 9665;
    }
    getEras() {
        return [
            'AH'
        ];
    }
    constructor(){
        this.identifier = 'islamic-civil';
    }
}
class $a938ddf4fc940323$export$37f0887f2f9d22f7 extends $a938ddf4fc940323$export$2066795aadd37bfc {
    fromJulianDay(jd) {
        return $a938ddf4fc940323$var$julianDayToIslamic(this, $a938ddf4fc940323$var$ASTRONOMICAL_EPOC, jd);
    }
    toJulianDay(date) {
        return $a938ddf4fc940323$var$islamicToJulianDay($a938ddf4fc940323$var$ASTRONOMICAL_EPOC, date.year, date.month, date.day);
    }
    constructor(...args){
        super(...args), this.identifier = 'islamic-tbla';
    }
}
// Generated by scripts/generate-umalqura.js
const $a938ddf4fc940323$var$UMALQURA_DATA = 'qgpUDckO1AbqBmwDrQpVBakGkgepC9QF2gpcBS0NlQZKB1QLagutBa4ETwoXBYsGpQbVCtYCWwmdBE0KJg2VDawFtgm6AlsKKwWVCsoG6Qr0AnYJtgJWCcoKpAvSC9kF3AJtCU0FpQpSC6ULtAW2CVcFlwJLBaMGUgdlC2oFqworBZUMSg2lDcoF1gpXCasESwmlClILagt1BXYCtwhbBFUFqQW0BdoJ3QRuAjYJqgpUDbIN1QXaAlsJqwRVCkkLZAtxC7QFtQpVCiUNkg7JDtQG6QprCasEkwpJDaQNsg25CroEWworBZUKKgtVC1wFvQQ9Ah0JlQpKC1oLbQW2AjsJmwRVBqkGVAdqC2wFrQpVBSkLkgupC9QF2gpaBasKlQVJB2QHqgu1BbYCVgpNDiULUgtqC60FrgIvCZcESwalBqwG1gpdBZ0ETQoWDZUNqgW1BdoCWwmtBJUFygbkBuoK9QS2AlYJqgpUC9IL2QXqAm0JrQSVCkoLpQuyBbUJ1gSXCkcFkwZJB1ULagVrCisFiwpGDaMNygXWCtsEawJLCaUKUgtpC3UFdgG3CFsCKwVlBbQF2gntBG0BtgimClINqQ3UBdoKWwmrBFMGKQdiB6kLsgW1ClUFJQuSDckO0gbpCmsFqwRVCikNVA2qDbUJugQ7CpsETQqqCtUK2gJdCV4ELgqaDFUNsga5BroEXQotBZUKUguoC7QLuQXaAloJSgukDdEO6AZqC20FNQWVBkoNqA3UDdoGWwWdAisGFQtKC5ULqgWuCi4JjwwnBZUGqgbWCl0FnQI=';
let $a938ddf4fc940323$var$UMALQURA_MONTHLENGTH;
let $a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE;
function $a938ddf4fc940323$var$umalquraYearStart(year) {
    return $a938ddf4fc940323$var$UMALQURA_START_DAYS + $a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE[year - $a938ddf4fc940323$var$UMALQURA_YEAR_START];
}
function $a938ddf4fc940323$var$umalquraMonthLength(year, month) {
    let idx = year - $a938ddf4fc940323$var$UMALQURA_YEAR_START;
    let mask = 0x01 << 11 - (month - 1);
    if (($a938ddf4fc940323$var$UMALQURA_MONTHLENGTH[idx] & mask) === 0) return 29;
    else return 30;
}
function $a938ddf4fc940323$var$umalquraMonthStart(year, month) {
    let day = $a938ddf4fc940323$var$umalquraYearStart(year);
    for(let i = 1; i < month; i++)day += $a938ddf4fc940323$var$umalquraMonthLength(year, i);
    return day;
}
function $a938ddf4fc940323$var$umalquraYearLength(year) {
    return $a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE[year + 1 - $a938ddf4fc940323$var$UMALQURA_YEAR_START] - $a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE[year - $a938ddf4fc940323$var$UMALQURA_YEAR_START];
}
class $a938ddf4fc940323$export$5baab4758c231076 extends $a938ddf4fc940323$export$2066795aadd37bfc {
    fromJulianDay(jd) {
        let days = jd - $a938ddf4fc940323$var$CIVIL_EPOC;
        let startDays = $a938ddf4fc940323$var$umalquraYearStart($a938ddf4fc940323$var$UMALQURA_YEAR_START);
        let endDays = $a938ddf4fc940323$var$umalquraYearStart($a938ddf4fc940323$var$UMALQURA_YEAR_END);
        if (days < startDays || days > endDays) return super.fromJulianDay(jd);
        else {
            let y = $a938ddf4fc940323$var$UMALQURA_YEAR_START - 1;
            let m = 1;
            let d = 1;
            while(d > 0){
                y++;
                d = days - $a938ddf4fc940323$var$umalquraYearStart(y) + 1;
                let yearLength = $a938ddf4fc940323$var$umalquraYearLength(y);
                if (d === yearLength) {
                    m = 12;
                    break;
                } else if (d < yearLength) {
                    let monthLength = $a938ddf4fc940323$var$umalquraMonthLength(y, m);
                    m = 1;
                    while(d > monthLength){
                        d -= monthLength;
                        m++;
                        monthLength = $a938ddf4fc940323$var$umalquraMonthLength(y, m);
                    }
                    break;
                }
            }
            return new (0, $9a4e222e1bd2b190$export$99faa760c7908e4f)(this, y, m, days - $a938ddf4fc940323$var$umalquraMonthStart(y, m) + 1);
        }
    }
    toJulianDay(date) {
        if (date.year < $a938ddf4fc940323$var$UMALQURA_YEAR_START || date.year > $a938ddf4fc940323$var$UMALQURA_YEAR_END) return super.toJulianDay(date);
        return $a938ddf4fc940323$var$CIVIL_EPOC + $a938ddf4fc940323$var$umalquraMonthStart(date.year, date.month) + (date.day - 1);
    }
    getDaysInMonth(date) {
        if (date.year < $a938ddf4fc940323$var$UMALQURA_YEAR_START || date.year > $a938ddf4fc940323$var$UMALQURA_YEAR_END) return super.getDaysInMonth(date);
        return $a938ddf4fc940323$var$umalquraMonthLength(date.year, date.month);
    }
    getDaysInYear(date) {
        if (date.year < $a938ddf4fc940323$var$UMALQURA_YEAR_START || date.year > $a938ddf4fc940323$var$UMALQURA_YEAR_END) return super.getDaysInYear(date);
        return $a938ddf4fc940323$var$umalquraYearLength(date.year);
    }
    constructor(){
        super(), this.identifier = 'islamic-umalqura';
        if (!$a938ddf4fc940323$var$UMALQURA_MONTHLENGTH) $a938ddf4fc940323$var$UMALQURA_MONTHLENGTH = new Uint16Array(Uint8Array.from(atob($a938ddf4fc940323$var$UMALQURA_DATA), (c)=>c.charCodeAt(0)).buffer);
        if (!$a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE) {
            $a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE = new Uint32Array($a938ddf4fc940323$var$UMALQURA_YEAR_END - $a938ddf4fc940323$var$UMALQURA_YEAR_START + 1);
            let yearStart = 0;
            for(let year = $a938ddf4fc940323$var$UMALQURA_YEAR_START; year <= $a938ddf4fc940323$var$UMALQURA_YEAR_END; year++){
                $a938ddf4fc940323$var$UMALQURA_YEAR_START_TABLE[year - $a938ddf4fc940323$var$UMALQURA_YEAR_START] = yearStart;
                for(let i = 1; i <= 12; i++)yearStart += $a938ddf4fc940323$var$umalquraMonthLength(year, i);
            }
        }
    }
}


export {$a938ddf4fc940323$export$2066795aadd37bfc as IslamicCivilCalendar, $a938ddf4fc940323$export$37f0887f2f9d22f7 as IslamicTabularCalendar, $a938ddf4fc940323$export$5baab4758c231076 as IslamicUmalquraCalendar};
//# sourceMappingURL=IslamicCalendar.js.map
