<div class="flex flex-col gap-6">
  <app-card-data cardTitle="اطلاعات شریک تجاری" [editable]="true" [(editMode)]="editMode">
    <ng-template #moreActions>
      <p-button outlined size="small" (onClick)="openChargeAccountDialog()"> شارژ کاربر </p-button>
      <p-button outlined size="small" (onClick)="openChargeDialog()"> شارژ لایسنس‌ </p-button>
    </ng-template>
    <div class="flex flex-col gap-4">
      <div class="listKeyValue">
        <app-key-value label="عنوان شریک تجاری" [value]="partner()?.name" />
        <app-key-value label="کد شریک تجاری" [value]="partner()?.code" />

        <div class="col-span-3 grid grid-cols-3 gap-4 mt-6">
          <partner-license-info-template
            title="لایسنس‌ها"
            [total]="partner()?.licenses_status?.total || 0"
            [expired]="partner()?.licenses_status?.expired || 0"
            [activated]="partner()?.licenses_status?.used || 0"
            [remained]="
              (partner()?.licenses_status?.total || 0) -
              (partner()?.licenses_status?.used || 0) -
              (partner()?.licenses_status?.expired || 0)
            "
          />

          <partner-license-info-template
            title="شارژ کاربران"
            [total]="partner()?.account_quota_status?.total || 0"
            [expired]="partner()?.account_quota_status?.expired || 0"
            [activated]="partner()?.account_quota_status?.used || 0"
            [remained]="
              (partner()?.account_quota_status?.total || 0) -
              (partner()?.account_quota_status?.used || 0) -
              (partner()?.account_quota_status?.expired || 0)
            "
          />

          <partner-license-info-template
            title="تمدید لایسنس‌ها"
            [total]="partner()?.license_renew_status?.total || 0"
            [expired]="partner()?.license_renew_status?.expired || 0"
            [activated]="partner()?.license_renew_status?.used || 0"
            [remained]="
              (partner()?.license_renew_status?.total || 0) -
              (partner()?.license_renew_status?.used || 0) -
              (partner()?.license_renew_status?.expired || 0)
            "
          />
        </div>
        <!--
        <p-divider align="center" class="col-span-3">اطلاعات لایسنس‌ها</p-divider>
        <app-key-value type="number" label="مجموع لایسنس خریداری شده" [value]="partner()?.licenses_status?.total" />
        <app-key-value type="number" label="مجموع لایسنس منقضی شده" [value]="partner()?.licenses_status?.expired" />
        <app-key-value type="number" label="مجموع لایسنس فروخته شده" [value]="partner()?.licenses_status?.used" />
        <app-key-value
          type="number"
          label="مجموع لایسنس باقی‌مانده"
          [value]="
            (partner()?.licenses_status?.total || 0) -
            (partner()?.licenses_status?.used || 0) -
            (partner()?.licenses_status?.expired || 0)
          "
        />
        <p-divider align="center" class="col-span-3">اطلاعات شارژ کاربران</p-divider>
        <app-key-value
          type="number"
          label="مجموع کاربران خریداری شده"
          [value]="partner()?.account_quota_status?.total"
        />
        <app-key-value
          type="number"
          label="مجموع کاربران منقضی شده"
          [value]="partner()?.account_quota_status?.expired"
        />
        <app-key-value type="number" label="مجموع کاربران فروخته شده" [value]="partner()?.account_quota_status?.used" />
        <app-key-value
          type="number"
          label="مجموع کاربران باقی‌مانده"
          [value]="
            (partner()?.account_quota_status?.total || 0) -
            (partner()?.account_quota_status?.used || 0) -
            (partner()?.account_quota_status?.expired || 0)
          "
        />
        <p-divider align="center" class="col-span-3">اطلاعات تمدید لایسنس‌ها</p-divider>
        <app-key-value type="number" label="مجموع تمدید خریداری شده" [value]="partner()?.license_renew_status?.total" />
        <app-key-value type="number" label="مجموع تمدید منقضی شده" [value]="partner()?.license_renew_status?.expired" />
        <app-key-value type="number" label="مجموع تمدید فروخته شده" [value]="partner()?.license_renew_status?.used" />
        <app-key-value
          type="number"
          label="مجموع تمدید باقی‌مانده"
          [value]="
            (partner()?.license_renew_status?.total || 0) -
            (partner()?.license_renew_status?.used || 0) -
            (partner()?.license_renew_status?.expired || 0)
          "
        />-->
      </div>
    </div>
  </app-card-data>

  <div class="max-h-125 flex">
    <admin-partner-licenses [partnerId]="partnerId()" class="w-full" />
  </div>

  <div class="max-h-125 flex">
    <admin-partner-chargeLicenseTransaction-list [partnerId]="partnerId()" class="w-full" />
  </div>

  <div class="max-h-125 flex">
    <admin-partner-chargeAccount-list [partnerId]="partnerId()" class="w-full"></admin-partner-chargeAccount-list>
  </div>

  <div class="max-h-125 flex">
    <superAdmin-partner-account-list [partnerId]="partnerId()" class="w-full" />
  </div>
</div>

<partner-form
  [(visible)]="editMode"
  [editMode]="true"
  [partnerId]="partnerId()"
  [initialValues]="partner() || undefined"
  (onSubmit)="getData()"
/>

<partner-charge-license-form-dialog
  [(visible)]="visibleChargeFormDialog"
  [partnerId]="partnerId()"
  (onSubmit)="getData()"
/>

<admin-partner-charge-account-form-dialog
  [(visible)]="visibleChargeAccountFormDialog"
  [partnerId]="partnerId()"
  (onSubmit)="getData()"
></admin-partner-charge-account-form-dialog>
