import{LitElement as e,html as t,css as a}from"../../lit/index.js";import{LoremDataBehaviors as r}from"./lib/lorem-data-behaviors.js";class LoremData extends(r(e)){static get styles(){return[a`
        label {
          font-size: 80%;
          font-family: sans-serif;
        }
        textarea {
          width: 100%;
          height: 200px;
        }
      `]}static get tag(){return"lorem-data"}static get properties(){return{schemas:{type:Object}}}constructor(){super(),this.schemas={}}render(){return t`
      <button @click="${this.saveAll}">Save All</button>
      ${Object.keys(this.schemas||[]).map((e=>t`
          <p>
            <label>
              <a href="${this.saveDataUrl(this.schemas[e])}" download="${e}"
                >${e}:
              </a>
              <br />
              <textarea>${this.getJson(this.schemas[e])}</textarea>
            </label>
          </p>
        `))}
      <button @click="${this.saveAll}">Save All</button>
    `}saveAll(){this.shadowRoot&&this.shadowRoot.querySelectorAll("a")&&confirm(`Save the following: ${Object.keys(this.schemas).join(", ")}?`)&&this.shadowRoot.querySelectorAll("a").forEach((e=>e.click()))}getJson(e){return JSON.stringify(this.randomType(e))}saveDataUrl(e){let t=this.getJson(e),a=new Blob([t],{type:"octet/stream"});return globalThis.URL.createObjectURL(a)}get data(){let e={};return Object.keys(this.schemas||[]).forEach((t=>e[t]=this.randomType(this.schemas[t]))),e}get colors(){let e=globalThis.SimpleColorsSharedStyles.requestAvailability();return!(!e||!e.colors)&&Object.keys(e.colors)}filterQuery(e,t){return e.filter(record,(e=>t(record,e)))}addDays(e=new Date,t=0){return new Date(Date.parse(e)+864e5*t)}addHours(e=new Date,t=0){return new Date(Date.parse(e)+36e5*t)}addMinutes(e=new Date,t=0){return new Date(Date.parse(e)+6e4*t)}addSeconds(e=new Date,t=0){return new Date(Date.parse(e)+1e3*t)}addWeeks(e=new Date,t=0){return new Date(Date.parse(e)+6048e5*t)}addYears(e=new Date,t=0){return new Date(Date.parse(e)+31536e6*t)}dateFormat(e,t){return"string"==typeof e&&(e=new Date(e)),e?"long"===t?e.toLocaleDateString(void 0,{weekday:"long",year:"numeric",month:"long",day:"numeric"}):"short"===t?e.toLocaleDateString(void 0,{month:"long",day:"numeric"}):e.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"}):""}draw(e=[],t=0,a=t){let r=a-t,o=Math.random()*r,n=t+Math.floor(o),s=Math.max(0,n);return this.shuffle(e).slice(0,s)}randomArray(e={},t=1,a=4){let r=[];for(let o=this.randomNumber(t,a,1);o>0;o--)r.push(this.randomType(e));return r}randomAspect(e=200,t=1e3,a=200,r=1e3){return`${this.randomNumber(e,t,1)}/${this.randomNumber(a,r,1)}`}randomBool(){return Math.random()>=.5}randomColor(){return this.randomOption(this.colors)}randomDate(e=Date.now(),t="years",a=-3,r=3){return e+("milliseconds"===t?this.randomNumber(a,r):"seconds"===t?this.randomNumber(1e3*a,1e3*r):"minutes"===t?this.randomNumber(6e4*a,6e4*r):"hours"===t?this.randomNumber(36e5*a,36e5*r):"days"===t?this.randomNumber(864e5*a,864e5*r):"weeks"===t?this.randomNumber(6048e5*a,6048e5*r):this.randomNumber(31536e6*a,31536e6*r))}randomHex(){return`#${[0,0,0].map((e=>this.randomNumber(e,255).toString(16))).map((e=>e.length<2?`0${e}`:`${e}`)).join("")}`}randomIcon(e=!1){let t=this.randomOption(this.icons);return e?this.randomOption([...t,""]):t}randomPlaceImg(e,t,a="any"){return t=t||this.randomWeightedOption([{value:"",weight:12},{value:"greyscale",weight:4},{value:"sepia",weight:1}]),`//placeimg.com/${e=e||this.randomAspect()}/${a}${"greyscale"===t?"/greyscale":"sepia"===t?"/sepia":""}`}randomPicsum(e,t,a=0,r){let o=t||this.randomWeightedOption([{value:!1,weight:3},{value:!0,weight:1}])?["greyscale"]:[];return a>0&&o.push(`blur=${a}`),`https://picsum.photos/${r>-1?`id/${r}`:""}/${e=e||this.randomAspect()}/${0==o.length?"":`?${o.join("&")}`}`}randomKitten(e,t){return`https://placehold.co/${e=e||this.randomAspect()}`}randomFlickr(e,t=[],a=!1,r=-1){return`https://loremflickr.com/${e=e||this.randomAspect()}${0===t.length?"":`/${t.join(",")}${a?"/all":""}`}${r>-1?`?random=${r}`:""}`}randomImage(e,t,a,r){return a&&["man","woman","person"].includes(a)?this.randomProfileImage(e,a):void 0===r?this.randomPlaceImg(e,t,a):"any"===a?this.randomPicsum(e,t,void 0,r):this.randomFlickr(e,[a],!1,r)}randomImageData(e,t,a,r){return{src:this.randomImage(e,t,a,r),alt:`Random ${a?`${a} `:""}image${r?` #${r}`:""}`,longdesc:`This is a long description for image${r?` #${r}`:""}. ${this.randomParagraph(1,5)}`}}randomProfileImage(e,t,a){let r=e.split("/"),o=parseInt(r[0])*parseInt(r[1]),n=o<250?"thumb/":o<640?"med/":"",s=Math.random()<.5?"men":"women";return`https://randomuser.me/api/portraits/${n}${"man"===t?"men":"woman"===t?"women":s}/${a||this.randomNumber(1,90)}.jpg`}randomLink(e,t=1,a=4){let r=this.draw(this.words,t,a),o=e||this.randomOption(["url","pdf"]),n=this.randomOption(this.words),s="url"!==o?`.${o}`:"";return{url:`http://${n}.com/${r.join("/")}${s}`,text:r.length>0?r.join(" "):n,type:o}}randomNumber(e=0,t=100+e,a=1){return e+Math.floor(Math.random()*Math.floor((t-e)/a))*a}randomObject(e={}){let t={};return Object.keys(e).forEach((a=>t[a]=this.randomType(e[a]))),t}randomOption(e=[]){return e.length>0?e[Math.floor(Math.random()*Math.floor(e.length))]:void 0}randomParagraph(e=3,t=7,a,r){let o=[];for(let n=this.randomNumber(e,t);n>0;n--)o.push(this.randomSentence(a,r));return`${o.join(" ")}`}randomSentence(e=3,t=15){let a=[],r=this.randomWeightedOption([{value:".",weight:10},{value:"?",weight:3},{value:"!",weight:1}]);for(let r=this.randomNumber(e,t);r>0;r--)a.push(this.randomWord());return a[0]&&(a[0]=this.titleCase(a[0])),`${a.join(" ")}${r}`}randomType(e){let t;if(e.type)switch(e.type){case"array":t=this.randomArray(e.children,e.min,e.max);break;case"boolean":t=this.randomBool();break;case"color":t=this.randomColor();break;case"data":return e.data;case"date":t=this.randomDate(e.start,e.units,e.min,e.max);break;case"hex":t=this.randomHex();break;case"icon":t=this.randomIcon(e.includeNull);break;case"image":t=this.randomImage(e.aspect||this.randomAspect(),e.greyscale,e.topic,e.multiple);break;case"imageData":t=this.randomImageData(e.aspect,e.greyscale,e.topic,e.multiple);break;case"letter":t=this.randomOption("abcdefghijklmnopqrstuvwxyz");break;case"link":t=this.randomLink(e.filetype,e.minPath,e.maxPath);break;case"number":t=this.randomNumber(e.min,e.max,e.step);break;case"object":t=this.randomObject(e.schema);break;case"option":return e.weightedOptions?this.randomWeightedOption(e.weightedOptions):this.randomOption(e.options);case"paragraph":t=this.randomParagraph(e.min,e.max,e.wordMinPerSent,e.wordMaxPerSent);break;case"sentence":t=this.randomSentence(e.min,e.max);break;default:t=this.randomWord()}return t}randomWeightedOption(e=[]){return this.randomOption(e.map((e=>{let t=[];for(let a=0;a<e.weight;a++)t.push(e.value);return t})).flat())}randomWord(){return this.randomOption(this.words)}shuffle(e=[]){return e.sort(((e,t)=>Math.random()-Math.random()))}sortDates(e,t=!1){return e.sort(((e,a)=>{let r="string"==typeof e.date?Date.parse(e.date):e.date,o="string"==typeof a.date?Date.parse(a.date):a.date;return t?r-o:o-r}))}titleCase(e){return e.toLowerCase().split(" ").map((e=>e.replace(e[0],e[0].toUpperCase()))).join(" ")}updated(e){super.updated&&super.updated(e),e.forEach(((e,t)=>{}))}}customElements.define(LoremData.tag,LoremData);export{LoremData};