import {
  TaxOverrideTable,
  TaxRateLine,
  useTaxOverrideTable
} from "./chunk-KGHHGMDU.js";
import "./chunk-Q4UVXS46.js";
import {
  TaxRegionCard
} from "./chunk-PEXMLTJX.js";
import {
  getProvinceByIso2,
  isProvinceInCountry
} from "./chunk-N2TQXB44.js";
import "./chunk-QDPLZDMX.js";
import {
  useTaxRateTableQuery
} from "./chunk-MG4GKUJW.js";
import "./chunk-JRTZWK77.js";
import "./chunk-U2EI2ZLM.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import "./chunk-YN3FGNJM.js";
import "./chunk-KCHYLLVG.js";
import "./chunk-CVXKASWV.js";
import "./chunk-THHRRYRS.js";
import {
  SingleColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.js";
import "./chunk-Y7QKP6QU.js";
import "./chunk-RLRWDHME.js";
import "./chunk-K5324KIX.js";
import {
  useTaxRates
} from "./chunk-FV76G2D7.js";
import {
  taxRegionsQueryKeys,
  useTaxRegion
} from "./chunk-GHDLST2P.js";
import "./chunk-YVYYOBAE.js";
import "./chunk-L2NJPDUD.js";
import "./chunk-P7UBW2EI.js";
import "./chunk-MR6REQKT.js";
import "./chunk-EPSDO2MJ.js";
import "./chunk-BHEU34FL.js";
import "./chunk-W34KDYZA.js";
import "./chunk-II3CLUXA.js";
import "./chunk-XKEYHWBS.js";
import "./chunk-J2XUEO2E.js";
import "./chunk-656G74I2.js";
import "./chunk-VWPNMEOE.js";
import "./chunk-O72AIZUN.js";
import "./chunk-VUWAOX7H.js";
import "./chunk-5DKUSZQ7.js";
import "./chunk-DIAWPVYS.js";
import "./chunk-4U2BLH45.js";
import "./chunk-YAUGB4LD.js";
import "./chunk-A5DJIOHN.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import {
  fetchQuery
} from "./chunk-DTGEFKK4.js";
import "./chunk-NBMM2TZK.js";

// src/pages/settings/tax-regions/[id]/provinces/[province_id]/index.tsx
import { useLoaderData, useParams } from "react-router-dom";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/settings/tax-regions/[id]/provinces/[province_id]/_components/tax-region-detail-section.tsx
import { Badge, Container, Tooltip } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
var TaxRegionProvinceDetailSection = ({
  taxRegion
}) => {
  const { t } = useTranslation();
  const defaultRates = taxRegion.tax_rates.filter((r) => r.is_default === true);
  const showBage = defaultRates.length === 0;
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsx(
      TaxRegionCard,
      {
        taxRegion,
        type: "header",
        asLink: false,
        badge: showBage && /* @__PURE__ */ jsx(Tooltip, { content: t("taxRegions.fields.noDefaultRate.tooltip"), children: /* @__PURE__ */ jsx(Badge, { color: "orange", size: "2xsmall", className: "cursor-default", children: t("taxRegions.fields.noDefaultRate.label") }) })
      }
    ),
    defaultRates.map((rate) => {
      return /* @__PURE__ */ jsx(TaxRateLine, { taxRate: rate, isSublevelTaxRate: true }, rate.id);
    })
  ] });
};

// src/pages/settings/tax-regions/[id]/provinces/[province_id]/_components/tax-region-province-override-section.tsx
import { Container as Container2, Heading } from "@medusajs/ui";
import { keepPreviousData } from "@tanstack/react-query";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var PREFIX = "o";
var TaxRegionProvinceOverrideSection = ({
  taxRegion
}) => {
  const { t } = useTranslation2();
  const { searchParams, raw } = useTaxRateTableQuery({
    pageSize: PAGE_SIZE,
    prefix: PREFIX
  });
  const { tax_rates, count, isPending, isError, error } = useTaxRates(
    {
      ...searchParams,
      tax_region_id: taxRegion.id,
      is_default: false
    },
    {
      placeholderData: keepPreviousData
    }
  );
  const { table } = useTaxOverrideTable({
    count,
    data: tax_rates,
    pageSize: PAGE_SIZE,
    prefix: PREFIX
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(Container2, { className: "p-0", children: /* @__PURE__ */ jsx2(
    TaxOverrideTable,
    {
      isPending,
      table,
      count,
      action: {
        label: t("actions.create"),
        to: "overrides/create"
      },
      queryObject: raw,
      prefix: PREFIX,
      children: /* @__PURE__ */ jsx2(Heading, { level: "h2", children: t("taxRegions.taxOverrides.header") })
    }
  ) });
};

// src/pages/settings/tax-regions/[id]/provinces/[province_id]/loader.ts
var taxRegionDetailQuery = (id) => ({
  queryKey: taxRegionsQueryKeys.detail(id),
  queryFn: async () => fetchQuery(`/vendor/tax-regions/${id}`, { method: "GET" })
});
var taxRegionLoader = async ({ params }) => {
  const id = params.province_id;
  const query = taxRegionDetailQuery(id);
  return queryClient.ensureQueryData(query);
};

// src/pages/settings/tax-regions/[id]/provinces/[province_id]/breadcrumb.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
var TaxRegionDetailBreadcrumb = (props) => {
  const { province_id } = props.params || {};
  const { tax_region } = useTaxRegion(province_id, void 0, {
    initialData: props.data,
    enabled: Boolean(province_id)
  });
  if (!tax_region) {
    return null;
  }
  const countryCode = tax_region.country_code?.toUpperCase();
  const provinceCode = tax_region.province_code?.toUpperCase();
  const isValid = isProvinceInCountry(countryCode, provinceCode);
  return /* @__PURE__ */ jsx3("span", { children: isValid ? getProvinceByIso2(provinceCode) : provinceCode });
};

// src/pages/settings/tax-regions/[id]/provinces/[province_id]/index.tsx
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
var TaxRegionProvinceDetail = () => {
  const { province_id } = useParams();
  const initialData = useLoaderData();
  const {
    tax_region: taxRegion,
    isLoading,
    isError,
    error
  } = useTaxRegion(province_id, void 0, {
    initialData
  });
  if (isLoading || !taxRegion) {
    return /* @__PURE__ */ jsx4(SingleColumnPageSkeleton, { sections: 2 });
  }
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx4(SingleColumnPage, { data: taxRegion, children: /* @__PURE__ */ jsxs2(WidgetZone, { id: "tax-regions.province.detail.main", data: taxRegion, children: [
    /* @__PURE__ */ jsx4(TaxRegionProvinceDetailSection, { taxRegion }),
    /* @__PURE__ */ jsx4(TaxRegionProvinceOverrideSection, { taxRegion })
  ] }) });
};
var Component = TaxRegionProvinceDetail;
export {
  TaxRegionDetailBreadcrumb as Breadcrumb,
  Component,
  taxRegionLoader as loader
};
